Skip to content

Commit f8bfd02

Browse files
Created weatherforecast.py (TheAlgorithms#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 <[email protected]>
1 parent 4768735 commit f8bfd02

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

web_programming/current_weather.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pprint import pprint
2+
3+
import requests
4+
5+
APPID = "" # <-- Put your OpenWeatherMap appid here!
6+
URL_BASE = "http://api.openweathermap.org/data/2.5/weather"
7+
8+
9+
def current_weather(location: str = "Chicago", appid: str = APPID) -> dict:
10+
return requests.get(URL_BASE, params={"appid": appid, "q": location}).json()
11+
12+
13+
if __name__ == "__main__":
14+
while True:
15+
location = input("Enter a location:").strip()
16+
if location:
17+
pprint(current_weather(location))
18+
else:
19+
break

0 commit comments

Comments
 (0)