Skip to content

Instantly share code, notes, and snippets.

@lmergner
Created July 1, 2013 22:18
Show Gist options
  • Save lmergner/5905124 to your computer and use it in GitHub Desktop.
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.
#!/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