From c4cf6196aa7c62fd75d8ad57273c0bcfd4d27afa Mon Sep 17 00:00:00 2001 From: Finn Christiansen Date: Thu, 13 Jun 2024 22:46:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=20add=20workaround=20to=20receive?= =?UTF-8?q?=20prayer=20times=20for=20the=20next=207=20days=20(which=20is?= =?UTF-8?q?=20not=20persistet=20yet)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matrix_bot_praying_times/__main__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/matrix_bot_praying_times/__main__.py b/matrix_bot_praying_times/__main__.py index 276f707..ac63ed2 100644 --- a/matrix_bot_praying_times/__main__.py +++ b/matrix_bot_praying_times/__main__.py @@ -114,14 +114,16 @@ def get_praying_times(date: datetime.date, username) -> Dict[str, str]: def schedule_reminder(username) -> None: # TODO: add peristence for reminders - times = get_praying_times(datetime.date.today(), username) now = datetime.datetime.now(datetime.UTC) - for prayer, time in times.items(): - praying_time = datetime.datetime.fromisoformat(time) - if praying_time > now: - seconds = int((praying_time - now).total_seconds()) - message = "{} is at {}".format(prayer, praying_time.strftime("%H:%M")) - asyncio.ensure_future(remind(username, message, seconds - user_reminders[username] * 60)) + # as a workaround until it's finished schedule the next 7 days + for i in range(7): + times = get_praying_times(datetime.date.today() + datetime.timedelta(days=i), username) + for prayer, time in times.items(): + praying_time = datetime.datetime.fromisoformat(time) + if praying_time > now: + seconds = int((praying_time - now).total_seconds()) + message = "{} is at {}".format(prayer, praying_time.strftime("%H:%M")) + asyncio.ensure_future(remind(username, message, seconds - user_reminders[username] * 60)) async def remind(username, message, seconds) -> None: