Last active
August 29, 2015 14:06
-
-
Save epochblue/8f2789955116bfe725f5 to your computer and use it in GitHub Desktop.
A simple script for retrieving current Nashville weather.
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
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