Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,11 @@ def fetch_air_quality(city, api_key):
|
|
| 9 |
if response.status_code == 200:
|
| 10 |
try:
|
| 11 |
data = response.json()
|
| 12 |
-
if 'data' in data and 'aqi' in data['data'] and 'time' in data['data']:
|
| 13 |
aqi = data['data']['aqi']
|
| 14 |
timestamp = data['data']['time']['s']
|
| 15 |
# Assuming the API's timestamp is in UTC
|
| 16 |
timestamp_with_zone = f"{timestamp} UTC"
|
| 17 |
-
|
| 18 |
return {'City': city, 'AQI': aqi, 'Timestamp': timestamp_with_zone}
|
| 19 |
else:
|
| 20 |
return {'City': city, 'AQI': 'Data not available', 'Timestamp': 'N/A'}
|
|
|
|
| 9 |
if response.status_code == 200:
|
| 10 |
try:
|
| 11 |
data = response.json()
|
| 12 |
+
if 'data' in data and 'aqi' in data['data'] and 'time' in data['data'] and 's' in data['data']['time']:
|
| 13 |
aqi = data['data']['aqi']
|
| 14 |
timestamp = data['data']['time']['s']
|
| 15 |
# Assuming the API's timestamp is in UTC
|
| 16 |
timestamp_with_zone = f"{timestamp} UTC"
|
|
|
|
| 17 |
return {'City': city, 'AQI': aqi, 'Timestamp': timestamp_with_zone}
|
| 18 |
else:
|
| 19 |
return {'City': city, 'AQI': 'Data not available', 'Timestamp': 'N/A'}
|