Skip to content
Snippets Groups Projects
Commit 86195020 authored by thomaswoehlke's avatar thomaswoehlke
Browse files

### 0.0.18 Release

parent ced6c3ef
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 433 deletions
import os
from covid19.blueprints.ecdc.ecdc_model_import import EcdcImport
class EcdcServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'ECDC'
self.sub_category = 'European Centre for Disease Prevention and Control'
self.tablename = EcdcImport.__tablename__
self.cvsfile_name = "ecdc_europa_data.csv"
self.url_src = "https://opendata.ecdc.europa.eu/covid19/casedistribution/csv/"
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_ok = "downloaded: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
from flask import flash
from database import app
from covid19.blueprints.ecdc.ecdc_service_config import EcdcServiceConfig
class EcdcServiceDownload:
def __init__(self, database, config: EcdcServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" ECDC Service Download [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" ECDC Service Download [ready] ")
def download_file(self):
app.logger.info("------------------------------------------------------------")
app.logger.info(" download ECDC [begin]")
app.logger.info("------------------------------------------------------------")
app.logger.info(" download FILE: "+self.cfg.cvsfile_name+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
try:
os.makedirs(self.cfg.data_path, exist_ok=True)
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
app.logger.info("------------------------------------------------------------")
except RuntimeError as runtimeError:
app.logger.error("############################################################")
app.logger.error(" " + runtimeError + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
except AttributeError as attributeError:
app.logger.error("############################################################")
app.logger.error(attributeError)
app.logger.error("############################################################")
flash(message="error after downloading: " + self.cfg.cvsfile_path, category='error')
except Exception as exception:
app.logger.error("############################################################")
app.logger.error(exception)
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
finally:
app.logger.info(" download ECDC [done]")
msg = "downloaded: " + self.cfg.cvsfile_path+" from " + self.cfg.url_src
flash(msg)
return self
import os
from covid19.blueprints.owid.owid_model_import import OwidImport
class OwidServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'OWID'
self.sub_category = 'Our World in Data'
self.tablename = OwidImport.__tablename__
self.cvsfile_name = "owid-covid-data.csv"
self.url_src = "https://covid.ourworldindata.org/data/owid-covid-data.csv"
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_ok = "downloaded: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
import subprocess
from flask import flash
from database import app
from covid19.blueprints.owid.owid_service_config import OwidServiceConfig
class OwidServiceDownload:
def __init__(self, database, config: OwidServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" OWID Service Download [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" OWID Service Download [ready]")
def __download_with_subprocess_and_os_native_wget(self):
orig_workdir = os.getcwd()
os.chdir(self.cfg.data_path)
my_cmd = ['wget ' + self.cfg.url_src]
subprocess.Popen(my_cmd, shell=True)
os.chdir(orig_workdir)
return self
def download_file(self):
app.logger.info(" download - [begin] ")
app.logger.info("------------------------------------------------------------")
app.logger.info(" download FILE: "+self.cfg.cvsfile_name+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
try:
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
self.__download_with_subprocess_and_os_native_wget()
#data_file = wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
#app.logger.info(" " + data_file + " ")
except RuntimeError as runtimeError:
app.logger.error("############################################################")
app.logger.error(" " + runtimeError + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
except AttributeError as attributeError:
app.logger.error("############################################################")
app.logger.error(attributeError)
app.logger.error("############################################################")
flash(message="error after downloading: " + self.cfg.cvsfile_path, category='error')
except Exception as exception:
app.logger.error("############################################################")
app.logger.error(exception)
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
finally:
app.logger.info("------------------------------------------------------------")
app.logger.info(" download - [done] ")
msg = "downloaded: " + self.cfg.cvsfile_path+" from "+self.cfg.url_src
flash(msg)
return self
from datetime import date
import os
from covid19.blueprints.rki_bundeslaender.rki_bundeslaender_model_import import RkiBundeslaenderImport
class RkiBundeslaenderServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'RKI'
self.sub_category = 'Bundeslaender'
self.tablename = RkiBundeslaenderImport.__tablename__
self.url_src = "https://opendata.arcgis.com/datasets/ef4b445a53c1406892257fe63129a8ea_0.csv"
self.cvsfile_name = "RKI_COVID19__" + date.today().isoformat() + "__bundeslaender.csv"
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_ok = "downloaded: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
from flask import flash
from database import app
from covid19.blueprints.rki_bundeslaender.rki_bundeslaender_service_config import RkiBundeslaenderServiceConfig
class RkiBundeslaenderServiceDownload:
def __init__(self, database, config: RkiBundeslaenderServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" RKI Service Download [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" RKI Service Download [ready]")
def download_file(self):
app.logger.info(" download - RKI [begin] ")
app.logger.info("------------------------------------------------------------")
app.logger.info(" download FILE: "+self.cfg.cvsfile_path+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
try:
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
data_file = wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
app.logger.info("download success: " + data_file + " ")
except RuntimeError as runtimeError:
app.logger.error("############################################################")
app.logger.error(" " + runtimeError + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
except AttributeError as attributeError:
app.logger.error("############################################################")
app.logger.error(attributeError)
app.logger.error("############################################################")
flash(message="error after downloading: " + self.cfg.cvsfile_path, category='error')
except Exception as exception:
app.logger.error("############################################################")
app.logger.error(exception)
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
finally:
app.logger.info("")
app.logger.info("------------------------------------------------------------")
app.logger.info(" downloaded FILE: "+self.cfg.cvsfile_path+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
app.logger.info(" download - RKI [done] ")
msg = "downloaded: " + self.cfg.cvsfile_path+" from "+self.cfg.url_src
flash(msg)
return self
from datetime import date
import os
from covid19.blueprints.rki_landkreise.rki_landkreise_model_import import RkiLandkreiseImport
class RkiLandkreiseServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'RKI'
self.sub_category = 'Landkreise'
self.tablename = RkiLandkreiseImport.__tablename__
self.url_src = "https://opendata.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0.csv"
self.cvsfile_name = "RKI_COVID19__" + date.today().isoformat() + "__landkreise.csv"
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_ok = "downloaded: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
from flask import flash
from database import app
from covid19.blueprints.rki_landkreise.rki_landkreise_service_config import RkiLandkreiseServiceConfig
class RkiLandkreiseServiceDownload:
def __init__(self, database, config: RkiLandkreiseServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" RKI Landkreise Service Download [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" RKI Landkreise Service Download [ready]")
def download_file(self):
app.logger.info(" RKI Landkreise Service Download - download_file begin] ")
app.logger.info("------------------------------------------------------------")
app.logger.info(" download FILE: "+self.cfg.cvsfile_name+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
try:
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
data_file = wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
app.logger.info(" " + data_file + " ")
except RuntimeError as runtimeError:
app.logger.error("############################################################")
app.logger.error(" runtimeError " + runtimeError + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
except AttributeError as attributeError:
app.logger.error("############################################################")
app.logger.error(" attributeError " + attributeError + " ")
app.logger.error("############################################################")
flash(message="error after downloading: " + self.cfg.cvsfile_path, category='error')
except Exception as exception:
app.logger.error("############################################################")
app.logger.error(" exception " + exception + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
finally:
app.logger.info("------------------------------------------------------------")
app.logger.info(" RKI Landkreise Service Download - download_file [done] ")
msg = "downloaded: " + self.cfg.cvsfile_path+" from "+self.cfg.url_src
flash(msg)
return self
import os
from covid19.blueprints.rki_vaccination.rki_vaccination_model_import import RkiVaccinationImport
class RkiVaccinationServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'RKI'
self.sub_category = 'Vaccination'
self.tablename = RkiVaccinationImport.__tablename__
self.url_src = "https://impfdashboard.de/static/data/germany_vaccinations_timeseries_v2.tsv"
self.cvsfile_name = "germany_vaccinations_timeseries_v2.tsv"
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_job = "download FILE: "+self.cfg.cvsfile_name+" from "+self.cfg.url_src
self.msg_ok = "downloaded FILE: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
import subprocess
from flask import flash
from database import app
from covid19.blueprints.rki_vaccination.rki_vaccination_service_config import RkiVaccinationServiceConfig
class RkiVaccinationServiceDownload:
def __init__(self, database, config: RkiVaccinationServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" "+self.cfg+" Download Service [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" "+self.cfg+" Download Service [ready]")
def __log_error(self, error_msg: str):
flash_msg = self.cfg.msg_error + error_msg
flash(message=flash_msg, category='error')
app.logger.error("############################################################")
app.logger.error(flash_msg)
app.logger.error("############################################################")
return self
def __log_success(self, data_file):
app.logger.info(" download success: " + data_file + " ")
app.logger.info(self.cfg.msg_ok)
flash(self.cfg.msg_ok)
return self
def __prepare_download(self):
os.makedirs(self.cfg.data_path, exist_ok=True)
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
return self
def __download_with_wget(self, src_url: str, target_file_path: str):
data_file = wget.download(src_url, target_file_path)
self.__log_success(data_file)
return self
def __download_with_subprocess_and_os_native_wget(self):
orig_workdir = os.getcwd()
os.chdir(self.cfg.data_path)
my_cmd = ['wget ' + self.cfg.url_src]
subprocess.Popen(my_cmd, shell=True)
os.chdir(orig_workdir)
return self
def download_file(self):
app.logger.info(" download_file - "+self.cfg+" [begin] ")
app.logger.info("------------------------------------------------------------")
app.logger.info(self.cfg.msg_job)
app.logger.info("------------------------------------------------------------")
try:
self.__prepare_download()
self.__download_with_wget(self.cfg.url_src, self.cfg.cvsfile_path)
except RuntimeError as runtimeError:
self.__log_error(" RuntimeError: " + runtimeError + " ")
except OSError as osError:
self.__log_error(" OSError: " + osError + " ")
except AttributeError as attributeError:
self.__log_error(" AttributeError: " + attributeError + " ")
except Exception as exception:
self.__log_error(" Exception: " + exception)
finally:
app.logger.info("------------------------------------------------------------")
app.logger.info(" download_file - "+self.cfg+" [done] ")
return self
import os
from covid19.blueprints.who.who_model_import import WhoImport
class WhoServiceConfig:
def __init__(self):
self.limit_nr = 20
self.data_path = ".." + os.sep + ".." + os.sep + "data"
self.category = 'WHO'
self.sub_category = 'Cases and Deaths'
self.tablename = WhoImport.__tablename__
self.cvsfile_name = "WHO-COVID-19-global-data.csv"
self.url_src = "https://covid19.who.int/" + self.cvsfile_name
self.cvsfile_path = self.data_path + os.sep + self.cvsfile_name
self.msg_ok = "downloaded: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
self.msg_error = "while downloading: " + self.cfg.cvsfile_path + " from " + self.cfg.url_src
import os
import wget
from flask import flash
from database import app
from covid19.blueprints.who.who_service_config import WhoServiceConfig
class WhoServiceDownload:
def __init__(self, database, config: WhoServiceConfig):
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" WHO Service Download [init]")
app.logger.debug("------------------------------------------------------------")
self.__database = database
self.cfg = config
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" WHO Service Download [ready]")
def download_file(self):
app.logger.info(" download - [begin] ")
app.logger.info("------------------------------------------------------------")
app.logger.info(" download FILE: "+self.cfg.cvsfile_name+" from "+self.cfg.url_src)
app.logger.info("------------------------------------------------------------")
try:
if os.path.isfile(self.cfg.cvsfile_path):
os.remove(self.cfg.cvsfile_path)
data_file = wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
app.logger.info(" download success: " + data_file + " ")
flash(self.cfg.msg_ok)
except RuntimeError as runtimeError:
app.logger.error("############################################################")
app.logger.error(" " + runtimeError + " ")
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
except AttributeError as attributeError:
app.logger.error("############################################################")
app.logger.error(attributeError)
app.logger.error("############################################################")
flash(message="error after downloading: " + self.cfg.cvsfile_path, category='error')
except Exception as exception:
app.logger.error("############################################################")
app.logger.error(exception)
app.logger.error("############################################################")
flash(message="error while downloading: " + self.cfg.cvsfile_path, category='error')
finally:
app.logger.info("------------------------------------------------------------")
app.logger.info(" download - [done] ")
return self
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment