Created
July 1, 2013 22:18
-
-
Save lmergner/5905124 to your computer and use it in GitHub Desktop.
TextExpander snippet for printing current weather conditions to www.DailyMile.com workouts. Requires wunderground.com api key.
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
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
""" | |
Local Weather TextExpander Snippet | |
================================== | |
Quickly enter local weather conditions, specifically current temp | |
in www.dailymile.com workouts. This is useful for tracking | |
performance against temperature more closely than dailymile.com | |
currently allows with their pictures. | |
Requires a wunderground.com api key. | |
""" | |
__author__ = Luke Thomas Mergner <lmergner@gmail.com> | |
import json | |
from datetime import datetime | |
import urllib2 | |
try: | |
r = urllib2.urlopen("http://api.wunderground.com/api/<API KEY>/conditions/q/CA/Glendale.json") | |
except URLError as e: | |
if hassattr(e, 'reason'): | |
print('Failure: %s' % e.reason) | |
elif hassattr(e, 'code'): | |
print('Error Code: %s' % e.code) | |
data =json.loads(r.read()) | |
local = data['current_observation'] | |
# fahr = "\u2109" | |
# When I use the unicode for Fahrenheit (℉) in the print statement, it fails. | |
string = u"{:%I:%M %p}: {} at {} with {} mph winds.".format(datetime.now(), local['weather'], local['temp_f'], local['wind_mph']) | |
print(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment