From 7564a46c526d09a11ee7e9897b8ba4d33df3ad3e Mon Sep 17 00:00:00 2001
From: thomaswoehlke <thomas.woehlke@gmail.com>
Date: Tue, 19 Jan 2021 14:20:38 +0100
Subject: [PATCH] ### 0.0.9 Release * Fixed #18 /europe/update: Download *
 Fixed #19 /europe/update: Import File to DB * Issue #20 /europe/update:
 Update DB * Issue #21 update_date_reported * Issue #22 update_continent *
 Issue #23 update_country * Issue #24 update_data * Issue #3 ORM: 3NF for
 ecdc_europa_data_import * Issue #4 data update for 3NF
 ecdc_europa_data_import

---
 README.md                                     |  4 ++
 .../covid19/europe/europe_service_download.py |  4 +-
 .../covid19/europe/europe_service_import.py   |  2 +-
 .../covid19/europe/europe_service_update.py   | 42 +++++++++++++++----
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 80015956..a90bb5c7 100644
--- a/README.md
+++ b/README.md
@@ -194,6 +194,10 @@ class WhoGlobalDataImportTable(db.Model):
 * Fixed #18 /europe/update: Download
 * Fixed #19 /europe/update: Import File to DB
 * Issue #20 /europe/update: Update DB
+* Issue #21 update_date_reported
+* Issue #22 update_continent
+* Issue #23 update_country
+* Issue #24 update_data
 * Issue #3 ORM: 3NF for ecdc_europa_data_import
 * Issue #4 data update for 3NF ecdc_europa_data_import
 
diff --git a/org/woehlke/covid19/europe/europe_service_download.py b/org/woehlke/covid19/europe/europe_service_download.py
index 305f2eb7..f5e69384 100644
--- a/org/woehlke/covid19/europe/europe_service_download.py
+++ b/org/woehlke/covid19/europe/europe_service_download.py
@@ -28,9 +28,7 @@ class EuropeServiceDownload:
         os.makedirs('data', exist_ok=True)
         app.logger.info("------------------------------------------------------------")
         try:
-            data_file = wget.download(self.__url_src_data)
-            os.remove(self.__src_europa_cvsfile_name)
-            os.renames(data_file, self.__src_europa_cvsfile_name)
+            wget.download(self.__url_src_data, self.__src_europa_cvsfile_name)
             app.logger.info("------------------------------------------------------------")
         except Exception as error:
             app.logger.warning(error)
diff --git a/org/woehlke/covid19/europe/europe_service_import.py b/org/woehlke/covid19/europe/europe_service_import.py
index e41e0480..0774fe18 100644
--- a/org/woehlke/covid19/europe/europe_service_import.py
+++ b/org/woehlke/covid19/europe/europe_service_import.py
@@ -47,7 +47,7 @@ class EuropeServiceImport:
                         =row['notification_rate_per_100000_population_14-days']
                     )
                     db.session.add(o)
-                    if (k % 1000) == 0:
+                    if (k % 100) == 0:
                         db.session.commit()
                         app.logger.info("  import Europa  ...  " + str(k) + " rows")
                     k = k + 1
diff --git a/org/woehlke/covid19/europe/europe_service_update.py b/org/woehlke/covid19/europe/europe_service_update.py
index fc305cac..7e821810 100644
--- a/org/woehlke/covid19/europe/europe_service_update.py
+++ b/org/woehlke/covid19/europe/europe_service_update.py
@@ -1,7 +1,7 @@
 import os
 import psycopg2
 from database import db, app
-from org.woehlke.covid19.europe.europe_model import EuropeDataImportTable
+from org.woehlke.covid19.europe.europe_model import EuropeDataImportTable, EuropeDateReported
 
 
 class EuropeServiceUpdate:
@@ -21,23 +21,51 @@ class EuropeServiceUpdate:
     def __update_date_reported(self):
         app.logger.info(" __update_date_reported [begin]")
         app.logger.info("------------------------------------------------------------")
-        EuropeDataImportTable.remove_all()
+        EuropeDateReported.remove_all()
         result_date_rep = EuropeDataImportTable.get_date_rep()
         for result_item in result_date_rep:
             my_date_rep = result_item['date_rep']
-            year_week = result_item['year_week']
-            app.logger.info("| "+my_date_rep+" | "+year_week+" |")
+            my_year_week = result_item['year_week']
+            app.logger.info("| "+my_date_rep+" | "+my_year_week+" |")
+            o = EuropeDateReported(
+                date_rep=my_date_rep,
+                year_week=my_year_week
+            )
+            db.session.add(o)
+        db.session.commit()
         app.logger.info(" __update_date_reported [done]")
         app.logger.info("------------------------------------------------------------")
         return self
 
+    def __update_continent(self):
+        app.logger.info(" __update_continent [begin]")
+        app.logger.info("------------------------------------------------------------")
+        app.logger.info(" ... ")
+        app.logger.info(" __update_continent [done]")
+        app.logger.info("------------------------------------------------------------")
+        return self
+
+    def __update_country(self):
+        app.logger.info(" __update_country [begin]")
+        app.logger.info("------------------------------------------------------------")
+        app.logger.info(" ... ")
+        app.logger.info(" __update_country [done]")
+        app.logger.info("------------------------------------------------------------")
+        return self
+
+    def __update_data(self):
+        app.logger.info(" __update_data [begin]")
+        app.logger.info("------------------------------------------------------------")
+        app.logger.info(" ... ")
+        app.logger.info(" __update_data [done]")
+        app.logger.info("------------------------------------------------------------")
+        return self
+
     def update_db(self):
         app.logger.info(" update_db [begin]")
         app.logger.info("------------------------------------------------------------")
-        app.logger.info(" ... ")
-        app.logger.info(" ... TBD ... ")
         self.__update_date_reported()
-        app.logger.info(" ... ")
+        self.__update_continent()
         app.logger.info(" update_db [done]")
         app.logger.info("------------------------------------------------------------")
         return self
-- 
GitLab