Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Last active August 29, 2015 14:03
Show Gist options
  • Save amarinelli/6256f68186835e1fb62c to your computer and use it in GitHub Desktop.
Save amarinelli/6256f68186835e1fb62c to your computer and use it in GitHub Desktop.
Get city temperature in °C using openweathermap API
# -*- 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