forked from Covid-19-Response-Greece/covid19-greece-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_data.py
59 lines (47 loc) · 2.31 KB
/
update_data.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
# this script downloads the data from https://github.com/Covid-19-Response-Greece/covid19-data-greece
import os
import urllib.request
import sys
DOWNLOADS_DIR = './data/'
urls = [
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/all_countries/JohnsHopkinsCSSE/cleaned-data/timeseries_per_country.json',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/JohnsHopkinsCSSE/timeseries_greece.json',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/wikipedia/cases.csv',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/isMOOD/daily-info.json',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/isMOOD/regions.json',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/isMOOD/total-info.json',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/iMEdD-Lab/greece.csv',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/iMEdD-Lab/greeceTimeline.csv',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/iMEdD-Lab/greece_cases.csv',
'https://raw.githubusercontent.com/Covid-19-Response-Greece/covid19-data-greece/master/data/greece/iMEdD-Lab/greece_deaths.csv'
]
paths_to_store = [
'all_countries/JohnsHopkinsCSSE',
'greece/JohnsHopkinsCSSE',
'greece/wikipedia',
'greece/isMOOD',
'greece/isMOOD',
'greece/isMOOD',
'greece/iMEdD-Lab',
'greece/iMEdD-Lab',
'greece/iMEdD-Lab',
'greece/iMEdD-Lab'
]
def download():
print('Updating data ...')
if not os.path.exists(DOWNLOADS_DIR):
os.makedirs(DOWNLOADS_DIR)
for i in range(0, len(urls)):
url = urls[i]
path = paths_to_store[i]
name = url.rsplit('/', 1)[-1]
filename = os.path.join(DOWNLOADS_DIR + path, name)
try:
urllib.request.urlretrieve(url, filename)
except Exception as inst:
print(inst)
print('Encountered error')
sys.exit()
print('Done.')
if __name__ == '__main__':
download()