forked from psteinb/covid19-curve-your-city
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnyt.py
35 lines (27 loc) · 943 Bytes
/
nyt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pandas as pd
from rich import print
import sys
help_msg = """
Download the NYT COVID-19 dataset for all US counties,
then extract and summarize the past 20 days for a specified
county and state.
Usage: python3 {} [-h | --help] [-u | --update]
"""
if ("-h" or "--help") in sys.argv:
exit(help_msg.format(sys.argv[0]))
def filter_nyt(csv, county, state):
df = pd.read_csv(csv)
df = df[df["county"] == county]
df = df[df["state"] == state]
return df
def update_nyt(csv):
import urllib.request
nyt = "https://github.com/nytimes/covid-19-data/raw/master/us-counties.csv"
urllib.request.urlretrieve(nyt, filename=csv)
if ("-u" or "--update") in sys.argv:
update_nyt("nyt-counties.csv")
else:
print("Printing last 20 cases from Montgomery County.",
"To update the dataset, specify `--update` or `-u`")
df = filter_nyt("nyt-counties.csv", "Montgomery", "Maryland")
print(df.tail(n=20))