-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-tek-counts.py
59 lines (54 loc) · 1.73 KB
/
collect-tek-counts.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 Python script fetches Exposure Notification TEK count files for European Union countries from
# Trinity College Dublin's website (https://down.dsg.cs.tcd.ie/tact/tek-counts) and combines
# them into one CSV file, sorted by date.
import requests
from http import HTTPStatus
potentially_participating_countries = {
'BE': 'Belgium',
'EL': 'Greece',
'LT': 'Lithuania',
'PT': 'Portugal',
'BG': 'Bulgaria',
'ES': 'Spain',
'LU': 'Luxembourg',
'RO': 'Romania',
'CZ': 'Czechia',
'FR': 'France',
'HU': 'Hungary',
'SI': 'Slovenia',
'DK': 'Denmark',
'HR': 'Croatia',
'MT': 'Malta',
'SK': 'Slovakia',
'DE': 'Germany',
'IT': 'Italy',
'NL': 'Netherlands',
'FI': 'Finland',
'EE': 'Estonia',
'CY': 'Cyprus',
'AT': 'Austria',
'SE': 'Sweden',
'IE': 'Ireland',
'LV': 'Latvia',
'PL': 'Poland',
'IS': 'Iceland',
'NO': 'Norway',
'LI': 'Liechtenstein',
'CH': 'Switzerland',
}
total_lines = []
for (country_code, country_name) in potentially_participating_countries.items():
response = requests.get(f"https://down.dsg.cs.tcd.ie/tact/tek-counts/{country_code.lower()}-tek-times.csv")
if response.status_code == HTTPStatus.OK:
lines = response.content.decode('utf-8').splitlines()[1:] # omit the CSV header line
# filter out the dates before 01 sep 2020. Swap first and 2nd value in output.
for line in lines:
values = line.split(',')
if values[1] >= '2020-09-01':
total_lines.append("{},{},{},{}".format(values[1], values[0], values[2], values[3]))
# sort lines by date
total_lines.sort()
# print header and lines
print("Date,Country,TEKs,Cases")
for line in total_lines:
print(line)