forked from CloudLabsAI-Azure/Code-Generation-Refactoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather_script.py
More file actions
21 lines (18 loc) · 721 Bytes
/
weather_script.py
File metadata and controls
21 lines (18 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
def get_weather(city_name, api_key):
base_url = "http://api.openweathermap.org/data/2.5/weather?"
complete_url = base_url + "q=" + city_name + "&appid=" + api_key
response = requests.get(complete_url)
if response.status_code == 200:
data = response.json()
main = data['main']
weather = data['weather'][0]
print(f"City: {city_name}")
print(f"Temperature: {main['temp']}K")
print(f"Weather: {weather['description']}")
else:
print("City not found.")
if __name__ == "__main__":
city_name = input("Enter city name: ")
api_key = "your_api_key_here" # Replace with your actual API key
get_weather(city_name, api_key)