From f8bfd0244d54563ae93e1d7b6083128465c1006d Mon Sep 17 00:00:00 2001 From: Swapnanil Dutta <47251193+swapnanildutta@users.noreply.github.com> Date: Sat, 30 May 2020 20:55:06 +0530 Subject: [PATCH] Created weatherforecast.py (#2037) * Created weatherforecast.py Added weatherforecast.py to retrieve weather information of a location and return dictionary values. * Update weatherforecast.py * Update and rename weatherforecast.py to current_weather.py Co-authored-by: Christian Clauss --- web_programming/current_weather.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 web_programming/current_weather.py diff --git a/web_programming/current_weather.py b/web_programming/current_weather.py new file mode 100644 index 000000000..a35fff2d4 --- /dev/null +++ b/web_programming/current_weather.py @@ -0,0 +1,19 @@ +from pprint import pprint + +import requests + +APPID = "" # <-- Put your OpenWeatherMap appid here! +URL_BASE = "http://api.openweathermap.org/data/2.5/weather" + + +def current_weather(location: str = "Chicago", appid: str = APPID) -> dict: + return requests.get(URL_BASE, params={"appid": appid, "q": location}).json() + + +if __name__ == "__main__": + while True: + location = input("Enter a location:").strip() + if location: + pprint(current_weather(location)) + else: + break