Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
gorausa committed Nov 28, 2018
1 parent 15f2e02 commit 73e3d29e26aa8a96f93bbded3d8bc399059dbfac
Showing 1 changed file with 7 additions and 6 deletions.
@@ -1,14 +1,15 @@
import requests
import requests #This library is necessary to get access to URL and its data if a web allows.

'''The function is giving the temperature and short weather condition for a particular location. '''
def weather_ask(sentence):
try:
city = sentence
url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&APPID=f7d590dc5f61801f09e17f3922567a55'
url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&APPID=f7d590dc5f61801f09e17f3922567a55' #The variable city can be either from stored data (global variable) or from user input (when asking for a different location).
res = requests.get(url)
data = res.json()
temp = data['main']['temp']
temp_C = temp - 273.15
weather_description = data['weather'][0]['description']
data = res.json() #JSON format is necessary to get the data from the website.
temp = data['main']['temp'] #Choose which data wants to get from the web page, in this case, it is temperature.
temp_C = temp - 273.15 #Making conversion from Kelvin degrees into Celsius degrees.
weather_description = data['weather'][0]['description'] #Weather description data is taken from web page.
print('Temperature is: ', round(temp_C, 1), 'degree and', weather_description)
except:
print("Invalid command this is used by typing the following: weather in [city] OR weather for [city] where [city] is replaced with the city you want to find the weather for")

0 comments on commit 73e3d29

Please sign in to comment.