covid-19-analysis/DataFetcher.py

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')