-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.py
More file actions
24 lines (21 loc) · 826 Bytes
/
Project.py
File metadata and controls
24 lines (21 loc) · 826 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
import requests
def get_weather(city, api_key):
base_url = "http://api.openweathermap.org/data/2.5/weather"
params = {
'q': city,
'appid': api_key,
'units': 'metric'
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
data = response.json()
weather = data['weather'][0]['description']
temperature = data['main']['temp']
print(f"Weather in {city}: {weather}")
print(f"Temperature: {temperature}°C")
else:
print(f"Failed to get weather data for {city}. Error code: {response.status_code}")
if __name__ == "__main__":
city = input("Enter city name: ")
api_key = "6383f2808a896c0ae6743d360aa7e7cf" # Replace with your actual API key
get_weather(city, api_key)