2020-05-30 15:25:06 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
APPID = "" # <-- Put your OpenWeatherMap appid here!
|
2022-10-16 07:43:29 +00:00
|
|
|
URL_BASE = "https://api.openweathermap.org/data/2.5/"
|
2020-05-30 18:17:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def current_weather(q: str = "Chicago", appid: str = APPID) -> dict:
|
|
|
|
"""https://openweathermap.org/api"""
|
|
|
|
return requests.get(URL_BASE + "weather", params=locals()).json()
|
2020-05-30 15:25:06 +00:00
|
|
|
|
|
|
|
|
2020-05-30 18:17:26 +00:00
|
|
|
def weather_forecast(q: str = "Kolkata, India", appid: str = APPID) -> dict:
|
|
|
|
"""https://openweathermap.org/forecast5"""
|
|
|
|
return requests.get(URL_BASE + "forecast", params=locals()).json()
|
|
|
|
|
|
|
|
|
|
|
|
def weather_onecall(lat: float = 55.68, lon: float = 12.57, appid: str = APPID) -> dict:
|
|
|
|
"""https://openweathermap.org/api/one-call-api"""
|
|
|
|
return requests.get(URL_BASE + "onecall", params=locals()).json()
|
2020-05-30 15:25:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-05-30 18:17:26 +00:00
|
|
|
from pprint import pprint
|
|
|
|
|
2020-05-30 15:25:06 +00:00
|
|
|
while True:
|
|
|
|
location = input("Enter a location:").strip()
|
|
|
|
if location:
|
|
|
|
pprint(current_weather(location))
|
|
|
|
else:
|
|
|
|
break
|