Permalink
Cannot retrieve contributors at this time
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?
CHATBOT/weather.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (23 sloc)
1022 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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') |