-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.py
More file actions
33 lines (23 loc) · 769 Bytes
/
weather.py
File metadata and controls
33 lines (23 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
API_KEY = "API_KEY"
def get_weather(city):
url = f"https://api.openweathermap.org/data/2.5/weather"
params = {
"q": city,
"appid": API_KEY,
"units": "metric"
}
response = requests.get(url, params=params)
if response.status_code != 200:
print("Error fetching weather data.")
return
data = response.json()
print("\n Weather Report")
print("----------------")
print("City:", data["name"])
print("Temperature:", data["main"]["temp"], "°C")
print("Feels like:", data["main"]["feels_like"], "°C")
print("Humidity:", data["main"]["humidity"], "%")
print("Conditions:", data["weather"][0]["description"])
city = input("Enter city name: ")
get_weather(city)