ninooo96 commited on
Commit
4493cff
·
verified ·
1 Parent(s): ff679d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -50,11 +50,12 @@ def get_weather(city: str) -> str:
50
  latitude = data['results'][0]['latitude']
51
  longitude = data['results'][0]['longitude']
52
 
53
- url = f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true&temperature_unit=celsius" # In Celsius
54
- response = requests.get(url)
55
- if response.status_code == 200:
56
- temperature = data['main']['temp']
57
- return f"{temperature} °C"
 
58
  else:
59
  return "Error on fetching weather data."
60
  else:
 
50
  latitude = data['results'][0]['latitude']
51
  longitude = data['results'][0]['longitude']
52
 
53
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true&temperature_unit=celsius" # In Celsius
54
+ weather_response = requests.get(weather_url)
55
+ if weather_response.status_code == 200:
56
+ weather_data = weather_response.json()
57
+ temperature = weather_data['current_weather']['temperature']
58
+ return f"The current weather on {city} is {temperature}"
59
  else:
60
  return "Error on fetching weather data."
61
  else: