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

update data

parent 6f1808f7
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
import os
import wget
import subprocess
from flask import flash
# from flask import flash
from database import app
from covid19.blueprints.application.application_service_config import ApplicationServiceConfig
......@@ -16,20 +16,20 @@ class ApplicationServiceDownload:
app.logger.debug("------------------------------------------------------------")
app.logger.debug(" ApplicationServiceDownload [ready]")
def __log_error(self, error_msg: str, error_obj):
log_msg = self.cfg.slug[0] + " " + self.cfg.msg_error() + " " + error_msg + " "
app.logger.error(log_msg)
flash(message=log_msg, category='error')
return self
def __log_success(self, data_file):
slug = self.cfg.slug[0]
log_msg1 = " " + slug + " | download success: " + data_file + " "
log_msg2 = " " + slug + " | " + self.cfg.msg_ok
app.logger.info(log_msg1)
app.logger.info(log_msg2)
flash(log_msg1)
return self
#def __log_error(self, error_msg: str, error_obj):
# log_msg = self.cfg.slug[0] + " " + self.cfg.msg_error() + " " + error_msg + " "
# app.logger.error(log_msg)
# flash(message=log_msg, category='error')
# return self
#
#def __log_success(self, data_file):
# slug = self.cfg.slug[0]
# log_msg1 = " " + slug + " | download success: " + data_file + " "
# log_msg2 = " " + slug + " | " + self.cfg.msg_ok
# app.logger.info(log_msg1)
# app.logger.info(log_msg2)
# flash(log_msg1)
# return self
def __prepare_download(self):
os.makedirs(self.cfg.data_path, exist_ok=True)
......@@ -39,17 +39,18 @@ class ApplicationServiceDownload:
def __download_with_wget(self):
data_file = wget.download(self.cfg.url_src, self.cfg.cvsfile_path)
self.__log_success(data_file)
app.logger.info(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)
# subprocess.Popen(my_cmd, shell=True)
retcode = subprocess.call(my_cmd, shell=True)
app.logger.info(retcode)
os.chdir(orig_workdir)
self.__log_success(my_cmd[0])
app.logger.info(my_cmd[0])
return self
def download_file(self):
......@@ -64,13 +65,17 @@ class ApplicationServiceDownload:
else:
self.__download_with_wget()
except RuntimeError as runtimeError:
self.__log_error(" RuntimeError: ", runtimeError)
app.logger.error(" RuntimeError: ")
app.logger.error(runtimeError)
except OSError as osError:
self.__log_error(" OSError: ", osError)
app.logger.error(" OSError: ")
app.logger.error(osError)
except AttributeError as attributeError:
self.__log_error(" AttributeError: ", attributeError)
app.logger.error(" AttributeError: ")
app.logger.error(attributeError)
except Exception as exception:
self.__log_error(" Exception: ", exception)
app.logger.error(" Exception: ")
app.logger.error(exception)
finally:
app.logger.info("------------------------------------------------------------")
app.logger.info(" download_file - [done] ")
......
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