Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_weather(city):
- search_url = "https://www.metaweather.com/api/location/search/?query=" + city
- result = requests.get(search_url)
- data = result.json()
- if not data:
- print("city not found")
- return
- cityID = data[0]['woeid']
- weather_url = "https://www.metaweather.com/api/location/" + str(cityID)
- result = requests.get(weather_url)
- data = result.json()
- #print(data['consolidated_weather'][1]['the_temp'])
- for element in data['consolidated_weather']:
- # print(element['applicable_date'] + ' '+ str(element['the_temp']))
- text = "In {city} on {date} the temperature is {temp}".format(city = city , date = element['applicable_date'], temp = element["the_temp"])
- print(text)
- cities = ["Munich", "Hamburg", "Dubai", "Berlin", "Bangkok"]
- for element in cities:
- get_weather(element)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement