Initial data pull

This commit is contained in:
Ian Gulliver
2020-03-22 05:29:19 +00:00
parent 08520ef588
commit f7e7a4fef5
2 changed files with 114 additions and 0 deletions

57
covid.py Executable file
View 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
View 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
1 State Population
2 AL 4903185
3 AK 731545
4 AZ 7278717
5 AR 3017825
6 AS 55641
7 CA 39512223
8 CO 5758736
9 CT 3565287
10 DE 973764
11 DC 705749
12 FL 21477737
13 GA 10617423
14 GU 165718
15 HI 1415872
16 ID 1792065
17 IL 12671821
18 IN 6732219
19 IA 3155070
20 KS 2913314
21 KY 4467673
22 LA 4648794
23 ME 1344212
24 MD 6045680
25 MA 6949503
26 MI 9986857
27 MN 5639632
28 MS 2976149
29 MO 6137428
30 MP 55194
31 MT 1068778
32 NE 1934408
33 NV 3080156
34 NH 1359711
35 NJ 8882190
36 NM 2096829
37 NY 19453561
38 NC 10488084
39 ND 762062
40 OH 11689100
41 OK 3956971
42 OR 4217737
43 PA 12801989
44 PR 3193694
45 RI 1059361
46 SC 5148714
47 SD 884659
48 TN 6833174
49 TX 28995881
50 UT 3205958
51 VT 623989
52 VA 8535519
53 VI 104914
54 WA 7614893
55 WV 1787147
56 WI 5822434
57 WY 578759