Skip to content

Instantly share code, notes, and snippets.

@epochblue
Last active August 29, 2015 14:06
Show Gist options
  • Save epochblue/8f2789955116bfe725f5 to your computer and use it in GitHub Desktop.
Save epochblue/8f2789955116bfe725f5 to your computer and use it in GitHub Desktop.
A simple script for retrieving current Nashville weather.
import os
import json
import urllib2
import contextlib
URL='http://api.openweathermap.org/data/2.5/weather?q=Nashville,TN&units=imperial'
with contextlib.closing(urllib2.urlopen(URL)) as r:
response = json.loads(r.read())
if response:
text = response.get('weather')[0].get('description')
temp = response.get('main').get('temp')
print u'{0}, {1}\u00B0f'.format(text, int(temp)).lower()
else:
print u'Unable to retrieve weather information.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment