forked from noahgift/myrepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
executable file
·60 lines (49 loc) · 2.1 KB
/
cli.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""
Commandline tool for interacting with library
"""
import click, pandas as pd, pickle
from click import echo
from myrepolib import __version__
def green(s):
return click.style(s, fg='green')
urls = {
'cases': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv',
'deaths': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv',
'recovered': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv',
'latest': 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/web-data/data/cases_country.csv',
}
def req_and_save(category):
url = urls[category]
echo("")
echo(f"Retrieving {green(category)} from {green(url)}")
df = pd.read_csv(url)
path = f"./data/{category}.df"
echo(f"Saving retrieved data to {green(path)}")
pickle.dump(df,open(path, 'wb'))
return df
@click.version_option(__version__)
@click.command()
@click.option("--category", help="retreive covid19 data from github")
def cli(category):
"""
retreive covid19 data from github by category
four valid values: cases, deaths, recovered, latest, all
cases will retrieve time series data of cases
deaths will retreve time series data of total number of deaths
recovered will retrieve time series data of total number of recovered cases
latest will retreive latest data of all category by country/region
all will retrieve all types of data
all data will be saved in pickle format in ./data folder
"""
if category in urls or category == 'all':
if category == 'all':
for category in urls:
req_and_save(category)
else:
req_and_save(category)
else:
click.echo(f"{click.style(category, bg='yellow', fg='red')} not valid")
if __name__ == '__main__':
#pylint: disable=no-value-for-parameter
cli()