Update app.py
Browse files
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
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 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
|