Last active
November 6, 2019 02:18
-
-
Save spudtrooper/ae27b08b12061c6b6106dad438ad0b0c to your computer and use it in GitHub Desktop.
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
"""Print out nytimes kentucky governors results | |
e.g. | |
while [[ 1 ]]; do echo; echo ; date; python ./nytimes.py; sleep 5; done | |
""" | |
import urllib, json | |
def main(): | |
url = 'https://int.nyt.com/applications/elections/2019/data/api/2019-11-05/kentucky/governor.json' | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
race = data['data']['races'][0] | |
reporting_display = race['reporting_display'] | |
precincts_reporting = int(race['precincts_reporting']) | |
precincts_total = int(race['precincts_total']) | |
votes = int(race['votes']) | |
result = race['result'] | |
print "precincts_reporting\t%d" % precincts_reporting | |
print "precincts_totalt\t%d" % precincts_total | |
print "reporting_display\t%s" % reporting_display | |
print "votes\t\t\t%d" % votes | |
print "result\t\t\t\t\t%s" % result | |
bevinm = 0 | |
besheara = 0 | |
hicksj = 0 | |
for c in race['counties']: | |
bevinm += int(c['results']['bevinm']) | |
besheara += int(c['results']['besheara']) | |
hicksj += int(c['results']['hicksj']) | |
diff = besheara-bevinm | |
votes_left = 13000.0 * (float(precincts_reporting) / float(precincts_total)) | |
besheara_perc = 100*(float(besheara)/float(votes)) | |
bevinm_perc = 100*(float(bevinm)/float(votes)) | |
perc_diff = besheara_perc-bevinm_perc | |
print "besheara\t%d\t%0.2f" % (besheara, besheara_perc) | |
print "bevinm\t\t%d\t%0.2f" % (bevinm, bevinm_perc) | |
print "hicksj\t\t%d\t%0.2f" % (hicksj, 100*(float(hicksj)/float(votes))) | |
print "diff\t\t%d\t%f" % (diff, perc_diff) | |
print "votes_left\t%d" % votes_left | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment