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
#Code for weather API
import requests
def getWeather(city, code):
try:
city.capitalize()
url = "https://community-open-weather-map.p.rapidapi.com/weather"
city.capitalize()
querystring = {"q":city+','+code,"lat":"0","lon":"0","callback":"test","id":"2172797","lang":"null","units":"metric","mode":"xml, html"}
headers = {
'x-rapidapi-key': "82f9448eb5msh9013e0006d93ae1p10e70ejsnad262f150737",
'x-rapidapi-host': "community-open-weather-map.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
apiList = str(response.text)
apiList = apiList.replace('"', '')
apiList = list(apiList.split(","))
for word in apiList:
#print(word)
if 'main:' in word:
temperature = word.replace('main:{temp:','')
if 'main:' in word and 'main:{temp:' not in word:
climate = word.replace('main:','')
country = code.upper()
return('Temperature in ' + city+', '+country +' is: ' + temperature +', '+climate)
except UnboundLocalError:
return('Sorry I have no results for this location')