Skip to content

Instantly share code, notes, and snippets.

@pca2
Created August 14, 2020 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pca2/dd9cd4efa1112090e43a4c2b937ef3ff to your computer and use it in GitHub Desktop.
Save pca2/dd9cd4efa1112090e43a4c2b937ef3ff to your computer and use it in GitHub Desktop.
538 2020 Presidential election model BitBar plugin
#!/usr/local/bin/python3
#Your shebang may need to be updated
'''
Todo:
1. check previous result and add up or down arrow result based on delta
2. include popular vote, other interesting fields
3. Senate(when it's available)
'''
import pandas as pd
pres = pd.read_csv('https://projects.fivethirtyeight.com/2020-general-data/presidential_national_toplines_2020.csv', delimiter=',')
biden_float = pres['ecwin_chal'][0]
trump_float = pres['ecwin_inc'][0]
last_updated = pres['timestamp'][0]
biden_prct = "{:.2%}".format(biden_float)
trump_prct = "{:.2%}".format(trump_float)
#Output
print(biden_prct)
print("---")
print(f"Trump: {trump_prct}")
print("---")
print(f"Last Update: {last_updated}")
print("---")
print("🦊 2020 Election Forecast | href=https://projects.fivethirtyeight.com/2020-election-forecast/")
print("Refresh... | refresh=true")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment