elstate.py
· 810 B · Python
Raw
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"] ))
| 1 | import urllib,json |
| 2 | d=json.loads(urllib.urlopen("https://intf.nyt.com/newsgraphics/2016/11-08-election-forecast/president.json").read())["president"] |
| 3 | print("""As of {timestamp}: |
| 4 | Clinton: |
| 5 | Votes: {electoral_votes_counted[clintonh]}/270 |
| 6 | Counted: {vote_share_counted[clintonh]:.3%} |
| 7 | Win prob: {win_prob[clintonh]:.3%} |
| 8 | Trump: |
| 9 | Votes: {electoral_votes_counted[trumpd]}/270 |
| 10 | Counted: {vote_share_counted[trumpd]:.3%} |
| 11 | Win prob: {win_prob[trumpd]:.3%}""".format(**d["timeseries"][-1])) |
| 12 | print("\n".join( "{state}: {current[winner][name_display]}".format(**s) if s["current"]["winner"] else |
| 13 | "{state}: Undecided, {current[percent_counted]:.1%} counted - Clinton: {current[win_prob][clintonh]:.1%}, Trump: {current[win_prob][trumpd]:.1%}".format(**s) |
| 14 | for s in d["races"] )) |