Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BEYOND_EUvsVirus
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thanassis Drivas
BEYOND_EUvsVirus
Commits
adb7a8ec
Commit
adb7a8ec
authored
Apr 25, 2020
by
Thanassis Drivas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload Main Script
parent
682f4034
Pipeline
#75
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
covid19_getdata.py
covid19_getdata.py
+37
-0
No files found.
covid19_getdata.py
0 → 100644
View file @
adb7a8ec
import
requests
import
csv
from
datetime
import
datetime
# set output filename
today
=
str
(
datetime
.
now
())
outputFilename
=
'results'
+
today
+
'.csv'
# ask and get data
response
=
requests
.
get
(
"https://opendata.ecdc.europa.eu/covid19/casedistribution/csv"
)
data
=
response
.
content
# transform data from string to array
data
=
data
.
split
(
'
\n
'
)
headings
=
data
[
0
]
values
=
data
[
1
:]
# create dictionaries based on ID
countriesCases
=
{}
countriesDeaths
=
{}
# loop over data
for
datarow
in
values
:
datarow
=
datarow
.
split
(
','
)
id
=
datarow
[
7
]
if
id
in
countriesCases
:
countriesCases
[
id
]
+=
int
(
datarow
[
4
])
countriesDeaths
[
id
]
+=
int
(
datarow
[
5
])
else
:
countriesCases
[
id
]
=
int
(
datarow
[
4
])
countriesDeaths
[
id
]
=
int
(
datarow
[
5
])
# create lists of lists sorted by country ID
toWrite
=
[[
"ID"
,
"CASES"
,
"DEATHS"
]]
for
key
in
sorted
(
countriesCases
.
keys
()):
toWrite
.
append
([
key
,
countriesCases
[
key
],
countriesDeaths
[
key
]])
# write results to file (alternatively: to database)
with
open
(
outputFilename
,
"wb"
)
as
f
:
writer
=
csv
.
writer
(
f
)
writer
.
writerows
(
toWrite
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment