typesdigital's picture
Update app.py
29c745c
raw
history blame
943 Bytes
import requests
import json
# Replace YOUR_API_KEY_HERE with your actual API key from OpenWeatherMap
api_key = "1aafc3163909c1493596da9340e00aee"
def get_weather(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'])
# Call the get_weather() function with a city name argument
get_weather("London")