typesdigital's picture
Create app.py
a2739ab
raw
history blame
898 Bytes
import requests
import json
# Replace YOUR_API_KEY_HERE with your actual API key from OpenWeatherMap
api_key = "1aafc3163909c1493596da9340e00aee"
# Enter the city name for which you want to retrieve the weather information
city_name = input("Enter city name: ")
# Make the API call to get the current weather details
url = f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}"
response = requests.get(url)
# Extract the relevant information from the response
if response.status_code == 200:
data = json.loads(response.content)
temperature = data['main']['temp']
description = data['weather'][0]['description']
wind_speed = data['wind']['speed']
print(f"Temperature: {temperature - 273.15:.1f} °C")
print(f"Weather Description: {description.title()}")
print(f"Wind Speed: {wind_speed} m/s")
else:
print(response.json()['message'])