pathologicalhandwaving
10/17/2015 - 3:09 AM

TextExpander snippet for printing current weather conditions to www.DailyMile.com workouts. Requires wunderground.com api key.

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)