Advertisement
Maszi

#feriechallenge HardCoder 2/10 :)

Jan 5th, 2021
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import requests
  2. import datetime
  3. import random
  4.  
  5. city = input("Choose city: ")
  6.  
  7. def calendar_day():
  8.     today = datetime.datetime.today()
  9.     print(f"""
  10.    Today we have {today.day} day of the {today.month} month {today.year} year
  11.    The day of the week is: {today.strftime('%A')}
  12.    Time now is {today.hour}:{today.strftime('%M')}""")
  13.  
  14. def weather_api():
  15.     querystring = {"q":"","lat":"0","lon":"0","id":"2172797","lang":"null","units":"metric" ,"mode":"xml, html"}
  16.     querystring["q"] = city
  17.  
  18.     url = "https://community-open-weather-map.p.rapidapi.com/weather"
  19.  
  20.     headers = {
  21.         'x-rapidapi-key': "83f6c748c0msh05c1107692f8917p14e71ajsnf6435b6b138a",
  22.         'x-rapidapi-host': "community-open-weather-map.p.rapidapi.com"
  23.         }
  24.  
  25.     response = requests.request("GET", url, headers=headers, params=querystring).json()
  26.     weather_info(response)
  27.  
  28. def weather_info(response):
  29.     if response:
  30.         print(f"""
  31.        Weather: {response['weather'][0]['main']}
  32.        Detailed weather: {response['weather'][0]['description']}
  33.        Temperature: {response['main']['temp']} C
  34.        Pressure: {response['main']['pressure']}""")
  35.     else:
  36.         print("Something goes wrong!")
  37.  
  38. def quote_of_the_day():
  39.     url_quote = "https://type.fit/api/quotes"
  40.     quote_response = random.choice(requests.request("GET", url_quote).json())
  41.     print(f"""
  42.    Quote for you today: {quote_response['text']}
  43.    Quote author: {quote_response['author']}""")
  44.  
  45. quote_of_the_day()
  46. calendar_day()
  47. weather_api()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement