Created
September 5, 2017 07:46
-
-
Save MKtalk/25a0f45dcff801ca562fc138881c7c88 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import requests | |
base_url = 'http://api.openweathermap.org/data/2.5/weather' | |
def get_weather(lat, lon, appid): | |
url = '{}?lat={}&lon={}&appid={}'.format(base_url, lat, lon, appid) | |
response = requests.get(url) | |
data = response.json() | |
country = data.get('sys')['country'] | |
name = data.get('name') | |
temp = float(data.get('main')['temp']) - 273.15 | |
wind = data.get('wind')['speed'] | |
cloud = data.get('weather')[0]['description'] | |
humidity = data.get('main')['humidity'] | |
message = ''' | |
Country: {}, {} | |
Temp: {} °C | |
Wind: {} m/s | |
Cooudiness: {} | |
Humidity: {} % | |
'''.format(name, country, round(temp, 1), wind, cloud, humidity) | |
return message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment