diff --git a/src/covid19/blueprints/application/application_model.py b/src/covid19/blueprints/application/application_model.py index 0f85612e123a4e8aff8ec3f1608b1a08f1774a63..e27101d07682a84ea224f0978207065f268b0968 100644 --- a/src/covid19/blueprints/application/application_model.py +++ b/src/covid19/blueprints/application/application_model.py @@ -43,7 +43,8 @@ class ApplicationDateReported(db.Model): return {1: "Montag", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Samstag", 7: "Sonntag"} - def __get_datum_parts(cls, my_date_rep: str): + @classmethod + def get_datum_parts(cls, my_date_rep: str): my_date_parts = my_date_rep.split("-") my_year = int(my_date_parts[0]) my_month = int(my_date_parts[1]) @@ -51,11 +52,13 @@ class ApplicationDateReported(db.Model): datum_parts = (my_year, my_month, my_day) return datum_parts - def __get_datum(cls, my_year: int, my_month: int, my_day: int): + @classmethod + def get_datum(cls, my_year: int, my_month: int, my_day: int): my_datum = date(my_year, my_month, my_day) return my_datum - def __get_datum_as_str(cls, my_year: int, my_month: int, my_day: int): + @classmethod + def get_datum_as_str(cls, my_year: int, my_month: int, my_day: int): my_datum_tp_be_stored = str(my_year) my_datum_tp_be_stored += "-" if my_month < 10: @@ -67,7 +70,8 @@ class ApplicationDateReported(db.Model): my_datum_tp_be_stored += str(my_day) return my_datum_tp_be_stored - def __my_year_week(cls, my_iso_year: int, week_number: int): + @classmethod + def my_year_week(cls, my_iso_year: int, week_number: int): my_year_week = "" + str(my_iso_year) if week_number < 10: my_year_week += "-0" @@ -78,11 +82,11 @@ class ApplicationDateReported(db.Model): @classmethod def create_new_object_factory(cls, my_date_rep: str): - (my_year, my_month, my_day) = cls.__get_datum_parts(my_date_rep) - date_reported = cls.__get_datum_as_str(my_year, my_month, my_day) - my_datum = cls.__get_datum(my_year, my_month, my_day) + (my_year, my_month, my_day) = cls.get_datum_parts(my_date_rep) + date_reported = cls.get_datum_as_str(my_year, my_month, my_day) + my_datum = cls.get_datum(my_year, my_month, my_day) (my_iso_year, week_number, weekday) = my_datum.isocalendar() - my_year_week = cls.__my_year_week(my_iso_year, week_number) + my_year_week = cls.my_year_week(my_iso_year, week_number) return ApplicationDateReported( date_reported=date_reported, datum=my_datum, diff --git a/src/covid19/blueprints/ecdc/ecdc_model.py b/src/covid19/blueprints/ecdc/ecdc_model.py index 5cdcb9b869ef306d8338384adb1c35ceda4ee543..c3586086b075c9efb4507fb47c568b56dabd5663 100644 --- a/src/covid19/blueprints/ecdc/ecdc_model.py +++ b/src/covid19/blueprints/ecdc/ecdc_model.py @@ -23,7 +23,8 @@ class EcdcDateReported(ApplicationDateReported): day_of_week = db.Column(db.Integer, nullable=False) week_of_year = db.Column(db.Integer, nullable=False) - def __get_datum_parts(cls, my_date_rep: str): + @classmethod + def get_datum_parts(cls, my_date_rep: str): my_date_parts = my_date_rep.split("/") my_year = int(my_date_parts[2]) my_month = int(my_date_parts[1]) @@ -33,11 +34,11 @@ class EcdcDateReported(ApplicationDateReported): @classmethod def create_new_object_factory(cls, my_date_rep: str): - (my_year, my_month, my_day) = cls.__get_datum_parts(my_date_rep) - date_reported = cls.__get_datum_as_str(my_year, my_month, my_day) - my_datum = cls.__get_datum(my_year, my_month, my_day) + (my_year, my_month, my_day) = cls.get_datum_parts(my_date_rep) + date_reported = super().get_datum_as_str(my_year, my_month, my_day) + my_datum = super().get_datum(my_year, my_month, my_day) (my_iso_year, week_number, weekday) = my_datum.isocalendar() - my_year_week = cls.__my_year_week(my_iso_year, week_number) + my_year_week = super().my_year_week(my_iso_year, week_number) return EcdcDateReported( date_reported=date_reported, datum=my_datum, diff --git a/src/covid19/blueprints/ecdc/ecdc_service_update.py b/src/covid19/blueprints/ecdc/ecdc_service_update.py index e3d067ed2b044c31253b4ec1c8001e4ef1a577c8..5a572f91be1bb64522edcfcb479ff39a5bc639d4 100644 --- a/src/covid19/blueprints/ecdc/ecdc_service_update.py +++ b/src/covid19/blueprints/ecdc/ecdc_service_update.py @@ -24,12 +24,14 @@ class EcdcServiceUpdate: k += 1 #my_date_rep = result_item['date_rep'] my_date_rep = result_item[0] - o = EcdcDateReported.create_new_object_factory( - my_date_rep=my_date_rep - ) - db.session.add(o) + oo = EcdcDateReported.find_by_date_reported(my_date_rep) + if oo is None: + o = EcdcDateReported.create_new_object_factory( + my_date_rep=my_date_rep + ) + db.session.add(o) + db.session.commit() app.logger.info("| " + my_date_rep + " | " + str(k) + " rows ") - db.session.commit() app.logger.info(" __update_date_reported [done]") app.logger.info("------------------------------------------------------------") return self