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
import requests
def weatherAPI(message):
"""Function that takes a string as input, where the string is the city, and returns the weather statistics
of said city"""
# Got this bit of code from a tutorial video: https://www.youtube.com/watch?v=PWZKTWJ9bJE
# defining url on which the bot will collect the data for the weather
url = 'http://api.openweathermap.org/data/2.5/weather?q={}&appid=bc755bd765c3ea2c47dade92eebc8c6b&units=metric'.format(
message)
# requests pings the url
response = requests.get(url)
# data collects the data from the url and stores it in a .json file
data = response.json()
# print(res)
# print(data)
temp = data['main']['temp']
wind_speed = data['wind']['speed']
latitude = data['coord']['lat']
longitude = data['coord']['lon']
description = data['weather'][0]['description']
# End of code obtained from tutorial video.
return "Temperature: {0} Cº \n" \
"Wind Speed: {1} km/h \n" \
"Latitude: {2} \n" \
"Longitude: {3} \n" \
"Description: {4}".format(temp,wind_speed,latitude,longitude,description)
# print('Temperature: {} degree celsius'.format(temp))
# print('Wind speed: {} m/h'.format(wind_speed))
# print('Latitude: {}'.format(latitude))
# print('Longitude: {}'.format(longitude))
# print('Description: {}'.format(description))
# if temp <= 0:
# print("Bot: You might see some snowman on your way to uni any time soon.")
# elif temp <= 10:
# print("Bot: It's pretty chilly out there, make sure you have your jacket at all times.")
# elif temp <= 20:
# print("Bot: It's not that bad out there, might consider getting an ice cream soon.")
# elif temp > 20:
# print("Bot: It's almost time to get the sunscreen out!")