2020-03-28 11:37:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Project: Analyse worldwide COVID-19 Data and provide graphs etc.
|
|
|
|
|
|
|
|
@author Patrick Müller
|
2020-03-29 09:45:00 +00:00
|
|
|
"""
|
|
|
|
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)
|
2020-03-31 14:24:42 +00:00
|
|
|
dateRepIndex = writeString.index('dateRep')
|
2020-03-29 09:45:00 +00:00
|
|
|
# Remove the first 2 characters and the very last character because these are some crap that we dont need
|
2020-03-31 14:24:42 +00:00
|
|
|
writeString = writeString[dateRepIndex:len(writeString)-1]
|
2020-03-29 09:45:00 +00:00
|
|
|
# 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()
|
2020-03-29 20:23:30 +00:00
|
|
|
print('DEBUG: Updated Stats File')
|