antfraia commited on
Commit
37655da
·
1 Parent(s): 16ddbf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -7,13 +7,14 @@ def get_weather(city_name, api_key):
7
  response = requests.get(complete_url)
8
  data = response.json()
9
 
10
- if data["cod"] != "404":
11
- main_data = data["main"]
12
- weather_data = data["weather"][0]
13
- temperature = main_data["temp"]
14
- pressure = main_data["pressure"]
15
- humidity = main_data["humidity"]
16
- weather_description = weather_data["description"]
 
17
  return temperature, pressure, humidity, weather_description
18
  else:
19
  return None
 
7
  response = requests.get(complete_url)
8
  data = response.json()
9
 
10
+ # Check if the API response was successful
11
+ if data.get("cod") == 200:
12
+ main_data = data.get("main", {})
13
+ weather_data = data.get("weather", [{}])[0]
14
+ temperature = main_data.get("temp", "N/A")
15
+ pressure = main_data.get("pressure", "N/A")
16
+ humidity = main_data.get("humidity", "N/A")
17
+ weather_description = weather_data.get("description", "N/A")
18
  return temperature, pressure, humidity, weather_description
19
  else:
20
  return None