forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent_weather.py
More file actions
Latest commit
30 lines (20 loc) · 948 Bytes
/
Copy pathcurrent_weather.py
File metadata and controls
30 lines (20 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
importrequests
APPID=""# <-- Put your OpenWeatherMap appid here!
URL_BASE="https://api.openweathermap.org/data/2.5/"
defcurrent_weather(q: str="Chicago", appid: str=APPID) ->dict:
"""https://openweathermap.org/api"""
returnrequests.get(URL_BASE+"weather", params=locals()).json()
defweather_forecast(q: str="Kolkata, India", appid: str=APPID) ->dict:
"""https://openweathermap.org/forecast5"""
returnrequests.get(URL_BASE+"forecast", params=locals()).json()
defweather_onecall(lat: float=55.68, lon: float=12.57, appid: str=APPID) ->dict:
"""https://openweathermap.org/api/one-call-api"""
returnrequests.get(URL_BASE+"onecall", params=locals()).json()
if__name__=="__main__":
frompprintimportpprint
whileTrue:
location=input("Enter a location:").strip()
iflocation:
pprint(current_weather(location))
else:
break