Skip to content

Instantly share code, notes, and snippets.

@segphault
Created November 6, 2008 19:37
Show Gist options
  • Save segphault/22684 to your computer and use it in GitHub Desktop.
Save segphault/22684 to your computer and use it in GitHub Desktop.
Retrieve data from Google's election tracker
#!/usr/bin/env python
import simplejson, urllib2
DATA_URL = "http://election2008.s3.amazonaws.com/votes/us-pres.json"
data = simplejson.loads(urllib2.urlopen(DATA_URL).read())
for candidate in data["totals"]["races"]["President"][""]["votes"]:
name = data["candidates"][candidate["id"]].split("|")[1]
print "%s: %s - %s" % (
name, candidate["votes"], candidate["electoral"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment