Last active
August 29, 2015 14:03
-
-
Save amarinelli/6256f68186835e1fb62c to your computer and use it in GitHub Desktop.
Get city temperature in °C using openweathermap API
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: cp1252 -*- | |
# Using http://openweathermap.org/ | |
import urllib2 | |
import json | |
def Convert(k): | |
return k - 273.15 | |
location = raw_input("Select a city: ") | |
url = r'http://api.openweathermap.org/data/2.5/weather?q=' + location | |
data = urllib2.urlopen(url) | |
js = json.load(data) | |
js2 = js['main'] | |
print "Current Temp in {0}: {1}°C".format(location, str(Convert(js2['temp']))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment