covid-19-analysis/DataFetcher.py

24 lines
826 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)
# Remove the first 2 characters and the very last character because these are some crap that we dont need
writeString = writeString[2: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()