Created
November 7, 2012 00:52
-
-
Save ipmb/4028826 to your computer and use it in GitHub Desktop.
Say election results
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 | |
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