diff --git a/mycaldav/models.py b/mycaldav/models.py index 8345bc0..d0fabdf 100644 --- a/mycaldav/models.py +++ b/mycaldav/models.py @@ -209,13 +209,14 @@ class cls_caldav_client(): with open(os.path.join("mycaldav", "last_sync_config.bin"), "rb") as file: array = pickle.load(file) except: - array = {"year": 0, "month": 0, "day": 0} + array = {"year": 0, "month": 0} print("Erreur lecture fichier config") - dt_today = datetime.today() - - if array["day"] == dt_today.day and array["month"] == dt_today.month: - print("pas de copy, sync déjà fait") + if array["month"] == datetime.now().month: + if array["year"] == datetime.now().year: + print("pas de copy, sync déjà fait") + else: + self.copy_caldav_data(self.a_task) else: self.copy_caldav_data(self.a_task) self.clear_all_events_by_Date(self.a_task) @@ -292,33 +293,32 @@ class cls_caldav_client(): event.save() - def get_ssl_context(self): + + + + + def copy_caldav_data(self, calandar=None): ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE - return ctx - - def copy_caldav_data_next_month(self, calandar=None): - pass - - def copy_caldav_data(self, calandar=None): - o_url = urllib.request.urlopen(self.caldav_agenda_config_url, context=self.get_ssl_context()) + + o_url = urllib.request.urlopen(self.caldav_agenda_config_url, context=ctx) data = o_url.read() o_url.close() - dt_today= datetime.today() - now = f"{dt_today.day}.{dt_today.month}.{dt_today.year}" + + now = f"01.{datetime.now().month}.{datetime.now().year}" - next_month = datetime.strptime(f"{dt_today.day}.{dt_today.month}.{dt_today.year}","%d.%m.%Y") + relativedelta(months=1) + next_month = datetime.strptime(f"1.{datetime.today().month}.{datetime.today().year}","%d.%m.%Y") + relativedelta(months=1) next_month = (next_month.year, next_month.month, next_month.day) - today = (dt_today.year, dt_today.month, dt_today.day) + today = (datetime.now().year, datetime.now().month, 1) print(f"today:{today}") print(f"next:{next_month}") events = None - events = recurring_ical_events.of(Calendar.from_ical(data)).between(next_month, next_month) + events = recurring_ical_events.of(Calendar.from_ical(data)).between(today, next_month) cur_events = calandar.date_search(start=datetime(today[0],today[1],today[2]), end=datetime(next_month[0],next_month[1],next_month[2]), expand=True) for event in events: @@ -336,7 +336,7 @@ class cls_caldav_client(): ) with open(os.path.join("mycaldav", "last_sync_config.bin"), "wb") as file: - array = {"year":dt_today.year, "month":dt_today.month, "day": dt_today.day} + array = {"year":datetime.now().year, "month":datetime.now().month} pickle.dump(array, file)