Spaces:
Runtime error
Runtime error
Commit
·
c6df024
1
Parent(s):
6e0aed9
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,23 @@
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
|
| 4 |
-
#
|
| 5 |
api_key = "1aafc3163909c1493596da9340e00aee"
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
response = requests.get(url)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
get_weather("London")
|
|
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
|
| 4 |
+
# Get an API key from https://openweathermap.org/api
|
| 5 |
api_key = "1aafc3163909c1493596da9340e00aee"
|
| 6 |
|
| 7 |
+
# Make a request to the OpenWeatherMap API
|
| 8 |
+
url = "https://api.openweathermap.org/data/2.5/weather?q=London&appid={}".format(api_key)
|
| 9 |
+
response = requests.get(url)
|
|
|
|
| 10 |
|
| 11 |
+
# Parse the response
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
# The request was successful
|
| 14 |
+
data = json.loads(response.content)
|
| 15 |
+
temperature = data['main']['temp']
|
| 16 |
+
description = data['weather'][0]['description']
|
| 17 |
+
wind_speed = data['wind']['speed']
|
| 18 |
+
print("Temperature: {} °C".format(temperature))
|
| 19 |
+
print("Weather Description: {}".format(description))
|
| 20 |
+
print("Wind Speed: {} m/s".format(wind_speed))
|
| 21 |
+
else:
|
| 22 |
+
# The request failed
|
| 23 |
+
print("Error: {}".format(response.json()['message']))
|
|
|