Skip to content

Instantly share code, notes, and snippets.

@blha303
Created November 9, 2016 06:23
Show Gist options
  • Save blha303/a3aa964af48378768aab787daaaab8c7 to your computer and use it in GitHub Desktop.
Save blha303/a3aa964af48378768aab787daaaab8c7 to your computer and use it in GitHub Desktop.
import urllib,json
d=json.loads(urllib.urlopen("https://intf.nyt.com/newsgraphics/2016/11-08-election-forecast/president.json").read())["president"]
print("""As of {timestamp}:
Clinton:
Votes: {electoral_votes_counted[clintonh]}/270
Counted: {vote_share_counted[clintonh]:.3%}
Win prob: {win_prob[clintonh]:.3%}
Trump:
Votes: {electoral_votes_counted[trumpd]}/270
Counted: {vote_share_counted[trumpd]:.3%}
Win prob: {win_prob[trumpd]:.3%}""".format(**d["timeseries"][-1]))
print("\n".join( "{state}: {current[winner][name_display]}".format(**s) if s["current"]["winner"] else
"{state}: Undecided, {current[percent_counted]:.1%} counted - Clinton: {current[win_prob][clintonh]:.1%}, Trump: {current[win_prob][trumpd]:.1%}".format(**s)
for s in d["races"] ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment