Spaces:
Runtime error
Runtime error
Commit
·
a2739ab
1
Parent(s):
0573f9c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Enter the city name for which you want to retrieve the weather information
|
8 |
+
city_name = input("Enter 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}"
|
12 |
+
response = requests.get(url)
|
13 |
+
|
14 |
+
# Extract the relevant information from the response
|
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")
|
22 |
+
print(f"Weather Description: {description.title()}")
|
23 |
+
print(f"Wind Speed: {wind_speed} m/s")
|
24 |
+
else:
|
25 |
+
print(response.json()['message'])
|