Spaces:
Runtime error
Runtime error
Commit
·
13e0925
1
Parent(s):
ca74202
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import requests
|
| 2 |
import json
|
|
|
|
| 3 |
|
| 4 |
# Replace YOUR_API_KEY_HERE with your actual API key from OpenWeatherMap
|
| 5 |
api_key = "1aafc3163909c1493596da9340e00aee"
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
city_name =
|
| 9 |
|
| 10 |
# Make the API call to get the current weather details
|
| 11 |
url = f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}"
|
|
@@ -15,7 +16,6 @@ response = requests.get(url)
|
|
| 15 |
if response.status_code == 200:
|
| 16 |
data = json.loads(response.content)
|
| 17 |
temperature = data['main']['temp']
|
| 18 |
-
|
| 19 |
description = data['weather'][0]['description']
|
| 20 |
wind_speed = data['wind']['speed']
|
| 21 |
print(f"Temperature: {temperature - 273.15:.1f} °C")
|
|
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
+
import sys
|
| 4 |
|
| 5 |
# Replace YOUR_API_KEY_HERE with your actual API key from OpenWeatherMap
|
| 6 |
api_key = "1aafc3163909c1493596da9340e00aee"
|
| 7 |
|
| 8 |
+
# Get the city name from the command line arguments
|
| 9 |
+
city_name = sys.argv[1]
|
| 10 |
|
| 11 |
# Make the API call to get the current weather details
|
| 12 |
url = f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}"
|
|
|
|
| 16 |
if response.status_code == 200:
|
| 17 |
data = json.loads(response.content)
|
| 18 |
temperature = data['main']['temp']
|
|
|
|
| 19 |
description = data['weather'][0]['description']
|
| 20 |
wind_speed = data['wind']['speed']
|
| 21 |
print(f"Temperature: {temperature - 273.15:.1f} °C")
|