Initial data pull
This commit is contained in:
57
covid.py
Executable file
57
covid.py
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import datetime
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class State:
|
||||||
|
def __init__(self, population):
|
||||||
|
self.Population = population
|
||||||
|
self.Snapshots = {}
|
||||||
|
|
||||||
|
def AddSnapshot(self, ts, positive, negative, pending, hospitalized, dead):
|
||||||
|
self.Snapshots[ts] = Snapshot(positive, negative, pending, hospitalized, dead)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.Population:>10}=pop {len(self.Snapshots):>4}=snaps'
|
||||||
|
|
||||||
|
|
||||||
|
class Snapshot:
|
||||||
|
def __init__(self, positive, negative, pending, hospitalized, dead):
|
||||||
|
self.Positive = positive
|
||||||
|
self.Negative = negative
|
||||||
|
self.Pending = pending
|
||||||
|
self.Hospitalized = hospitalized
|
||||||
|
self.Dead = dead
|
||||||
|
|
||||||
|
|
||||||
|
states = {}
|
||||||
|
|
||||||
|
|
||||||
|
def LoadPopulations():
|
||||||
|
with open('populations.csv', 'r') as fh:
|
||||||
|
reader = csv.DictReader(fh)
|
||||||
|
for row in reader:
|
||||||
|
states[row['State']] = State(int(row['Population']))
|
||||||
|
|
||||||
|
def LoadCovidTracking():
|
||||||
|
resp = requests.get('https://covidtracking.com/api/states/daily')
|
||||||
|
for row in resp.json():
|
||||||
|
ts = datetime.datetime.fromisoformat(row['dateChecked'][:-1])
|
||||||
|
states[row['state']].AddSnapshot(
|
||||||
|
ts,
|
||||||
|
row['positive'],
|
||||||
|
row['negative'],
|
||||||
|
row['pending'],
|
||||||
|
row['hospitalized'],
|
||||||
|
row['death'],
|
||||||
|
)
|
||||||
|
|
||||||
|
LoadPopulations()
|
||||||
|
LoadCovidTracking()
|
||||||
|
|
||||||
|
for code, state in sorted(states.items(), key=lambda x: x[1].Population):
|
||||||
|
print(f'{code} {state}')
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
57
populations.csv
Normal file
57
populations.csv
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
State,Population
|
||||||
|
AL,4903185
|
||||||
|
AK,731545
|
||||||
|
AZ,7278717
|
||||||
|
AR,3017825
|
||||||
|
AS,55641
|
||||||
|
CA,39512223
|
||||||
|
CO,5758736
|
||||||
|
CT,3565287
|
||||||
|
DE,973764
|
||||||
|
DC,705749
|
||||||
|
FL,21477737
|
||||||
|
GA,10617423
|
||||||
|
GU,165718
|
||||||
|
HI,1415872
|
||||||
|
ID,1792065
|
||||||
|
IL,12671821
|
||||||
|
IN,6732219
|
||||||
|
IA,3155070
|
||||||
|
KS,2913314
|
||||||
|
KY,4467673
|
||||||
|
LA,4648794
|
||||||
|
ME,1344212
|
||||||
|
MD,6045680
|
||||||
|
MA,6949503
|
||||||
|
MI,9986857
|
||||||
|
MN,5639632
|
||||||
|
MS,2976149
|
||||||
|
MO,6137428
|
||||||
|
MP,55194
|
||||||
|
MT,1068778
|
||||||
|
NE,1934408
|
||||||
|
NV,3080156
|
||||||
|
NH,1359711
|
||||||
|
NJ,8882190
|
||||||
|
NM,2096829
|
||||||
|
NY,19453561
|
||||||
|
NC,10488084
|
||||||
|
ND,762062
|
||||||
|
OH,11689100
|
||||||
|
OK,3956971
|
||||||
|
OR,4217737
|
||||||
|
PA,12801989
|
||||||
|
PR,3193694
|
||||||
|
RI,1059361
|
||||||
|
SC,5148714
|
||||||
|
SD,884659
|
||||||
|
TN,6833174
|
||||||
|
TX,28995881
|
||||||
|
UT,3205958
|
||||||
|
VT,623989
|
||||||
|
VA,8535519
|
||||||
|
VI,104914
|
||||||
|
WA,7614893
|
||||||
|
WV,1787147
|
||||||
|
WI,5822434
|
||||||
|
WY,578759
|
||||||
|
Reference in New Issue
Block a user