File tree Expand file tree Collapse file tree 1 file changed +41
-5
lines changed
Expand file tree Collapse file tree 1 file changed +41
-5
lines changed Original file line number Diff line number Diff line change 11
2- from io import StringIO
2+ import datetime
3+ from io import StringIO ,BytesIO
4+ import sys
5+ import zipfile
6+
37import pandas as pd
48import requests
59
6- def covid19 (file = "data-1.csv" ):
10+ URLs = {
11+ 1 : 'https://storage.covid19datahub.io/data-1.zip' ,
12+ 2 : 'https://storage.covid19datahub.io/data-2.zip' ,
13+ 3 : 'https://storage.covid19datahub.io/data-3.zip'
14+ }
15+ files = {
16+ 1 : 'data-1.csv' ,
17+ 2 : 'data-2.csv' ,
18+ 3 : 'data-3.csv'
19+ }
20+
21+ def covid19 (country = None ,
22+ level = 1 ,
23+ start = datetime .date (2019 ,1 ,1 ),
24+ end = None , # defaultly today
25+ raw = False ,
26+ vintage = False ,
27+ verbose = True ,
28+ cache = True ):
29+ # default today
30+ if not end :
31+ end = datetime .date .today ()
32+
33+ # get url from level
34+ try :
35+ url = URLs [level ]
36+ filename = files [level ]
37+ except KeyError :
38+ print ("Invalid level." , file = sys .stderr )
39+ return None
740 # download
8- url = f"https://storage.covid19datahub.io/{ file } "
941 response = requests .get (url )
1042 # parse
11- df = pd .read_csv ( StringIO (response .text ) )
12- return df
43+ with zipfile .ZipFile ( BytesIO (response .content ) ) as zz :
44+ with zz .open (filename ) as fd :
45+ x = pd .read_csv ( fd )
46+
47+
48+ return x
1349
1450__all__ = ["covid19" ]
You can’t perform that action at this time.
0 commit comments