covid-19-analysis/DataFetcher.py
Patrick Müller bd0bf56a1a 🐛 Fixed data fetcher
- Those fucking idiots at data.europa.eu somehow managed to fuck the data up by including some random string at the very beginning of the csv file.
- Also some small changes impacting performance
2020-03-31 16:24:42 +02:00

26 lines
920 B
Python

# -*- coding: utf-8 -*-
"""
Project: Analyse worldwide COVID-19 Data and provide graphs etc.
@author Patrick Müller
"""
import requests
import csv
def updateStatsFile():
url = 'https://opendata.ecdc.europa.eu/covid19/casedistribution/csv'
resp = requests.get(url, allow_redirects=True)
with open('statsfile.csv', 'w') as file:
# Save the fetched csv String to a variable to be able to mutate it
writeString = str(resp.content)
dateRepIndex = writeString.index('dateRep')
# Remove the first 2 characters and the very last character because these are some crap that we dont need
writeString = writeString[dateRepIndex:len(writeString)-1]
# Replace the crappy windows newline thingy with the beautiful unix newline char
writeString = writeString.replace('\\r\\n', '\n')
# Write the final string to the file
file.write(writeString)
# Done we are
file.close()
print('DEBUG: Updated Stats File')