Skip to content

Commit 5c90476

Browse files
authored
Update current_weather.py
1 parent f85241c commit 5c90476

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

web_programming/current_weather.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
import requests
22

3-
APPID = "" # <-- Put your OpenWeatherMap appid here!
4-
URL_BASE = "https://api.openweathermap.org/data/2.5/"
5-
6-
7-
def current_weather(q: str = "Chicago", appid: str = APPID) -> dict:
8-
"""https://openweathermap.org/api"""
9-
return requests.get(URL_BASE + "weather", params=locals()).json()
10-
11-
12-
def weather_forecast(q: str = "Kolkata, India", appid: str = APPID) -> dict:
13-
"""https://openweathermap.org/forecast5"""
14-
return requests.get(URL_BASE + "forecast", params=locals()).json()
15-
16-
17-
def weather_onecall(lat: float = 55.68, lon: float = 12.57, appid: str = APPID) -> dict:
18-
"""https://openweathermap.org/api/one-call-api"""
19-
return requests.get(URL_BASE + "onecall", params=locals()).json()
3+
API_KEY = "" # <-- Put your free Weatherstack API key here!
4+
URL_BASE = "http://api.weatherstack.com/current"
205

6+
def current_weather(location: str, api_key: str = API_KEY) -> dict:
7+
params = {
8+
"access_key": api_key,
9+
"query": location
10+
}
11+
return requests.get(URL_BASE, params=params).json()
2112

2213
if __name__ == "__main__":
2314
from pprint import pprint
2415

2516
while True:
26-
location = input("Enter a location:").strip()
17+
location = input("Enter a location (city name): ").strip()
2718
if location:
28-
pprint(current_weather(location))
19+
pprint(current_weather(location, API_KEY))
2920
else:
3021
break

0 commit comments

Comments
 (0)