Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
'''
API key for openweather API: e5329dd2891f08e84c9dc73b913bcab0
'''
import requests #this is an external library that i will use to make http requests to the Weather API
def get_weather(location):
'''make a weather query to API and uses the location as a parameter and returns the weather as a list of key info'''
weather_info=[]
url='https://api.openweathermap.org/data/2.5/weather?q={}&appid=e5329dd2891f08e84c9dc73b913bcab0&units=metric'.format(location)
response=requests.get(url)
data=response.json()
overview =(data['weather'][0]['main'])
description=(data['weather'][0]['description'])
temp=(data['main']['temp'])
wind_speed = (data['wind']['speed'])
location=data['name']
weather_info.append(overview) #--- summary description
weather_info.append(temp) #-- temperature
weather_info.append(description)
weather_info.append(wind_speed)
weather_info.append(location)
return weather_info
if __name__ == '__main__':
get_weather('london')