typesdigital's picture
Update app.py
527a822
raw
history blame
815 Bytes
import requests
import json
# Get an API key from https://openweathermap.org/api
api_key = "1aafc3163909c1493596da9340e00aee"
# Make a request to the OpenWeatherMap API
url = "https://api.openweathermap.org/data/2.5/weather?q=London&appid={}".format(api_key)
response = requests.get(url)
# Parse the response
if response.status_code == 200:
# The request was successful
data = json.loads(response.content)
temperature = data['main']['temp'] - 273.15
description = data['weather'][0]['description'].title()
wind_speed = data['wind']['speed']
print("Temperature: {} °C".format(temperature))
print("Weather Description: {}".format(description))
print("Wind Speed: {} m/s".format(wind_speed))
else:
# The request failed
print("Error: {}".format(response.json()['message']))