Spaces:
Sleeping
Sleeping
Update weather_model.py
Browse files- weather_model.py +0 -4
weather_model.py
CHANGED
|
@@ -3,18 +3,15 @@ from datetime import datetime, timedelta
|
|
| 3 |
|
| 4 |
def get_weather_data(city, days, api_key):
|
| 5 |
try:
|
| 6 |
-
# Geocode city to lat/lon
|
| 7 |
geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={api_key}"
|
| 8 |
geo_response = requests.get(geo_url).json()
|
| 9 |
if not geo_response:
|
| 10 |
return None
|
| 11 |
lat, lon = geo_response[0]['lat'], geo_response[0]['lon']
|
| 12 |
|
| 13 |
-
# Fetch weather data
|
| 14 |
url = f"http://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude=minutely,hourly&units=metric&appid={api_key}"
|
| 15 |
response = requests.get(url).json()
|
| 16 |
|
| 17 |
-
# Current weather
|
| 18 |
current = {
|
| 19 |
'temp': response['current']['temp'],
|
| 20 |
'weather': response['current']['weather'][0]['description'],
|
|
@@ -22,7 +19,6 @@ def get_weather_data(city, days, api_key):
|
|
| 22 |
'wind_speed': response['current']['wind_speed']
|
| 23 |
}
|
| 24 |
|
| 25 |
-
# Forecast
|
| 26 |
forecast = []
|
| 27 |
for i in range(min(days, len(response['daily']))):
|
| 28 |
day = response['daily'][i]
|
|
|
|
| 3 |
|
| 4 |
def get_weather_data(city, days, api_key):
|
| 5 |
try:
|
|
|
|
| 6 |
geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={api_key}"
|
| 7 |
geo_response = requests.get(geo_url).json()
|
| 8 |
if not geo_response:
|
| 9 |
return None
|
| 10 |
lat, lon = geo_response[0]['lat'], geo_response[0]['lon']
|
| 11 |
|
|
|
|
| 12 |
url = f"http://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude=minutely,hourly&units=metric&appid={api_key}"
|
| 13 |
response = requests.get(url).json()
|
| 14 |
|
|
|
|
| 15 |
current = {
|
| 16 |
'temp': response['current']['temp'],
|
| 17 |
'weather': response['current']['weather'][0]['description'],
|
|
|
|
| 19 |
'wind_speed': response['current']['wind_speed']
|
| 20 |
}
|
| 21 |
|
|
|
|
| 22 |
forecast = []
|
| 23 |
for i in range(min(days, len(response['daily']))):
|
| 24 |
day = response['daily'][i]
|