Skip to content

Instantly share code, notes, and snippets.

@ipmb
Created November 7, 2012 00:52
Show Gist options
  • Save ipmb/4028826 to your computer and use it in GitHub Desktop.
Save ipmb/4028826 to your computer and use it in GitHub Desktop.
Say election results
#!/usr/bin/env python
import time
import json
import urllib2
import subprocess
def check_results():
page = urllib2.urlopen('http://elections.nytimes.com/2012/results/president/big-board.json')
data = json.loads(page.read())
new_results = (str(data['tally']['dem_electoral_won']), str(data['tally']['gop_electoral_won']))
print "Latest data: {0}".format(new_results)
if new_results != RESULTS:
subprocess.call(['say', 'Obama', new_results[0]])
time.sleep(0.5)
subprocess.call(['say', 'Romney', new_results[1]])
return new_results
if __name__ == '__main__':
RESULTS = ('', '')
while True:
RESULTS = check_results()
# wait 1 minute
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment