From 90d97ee89e8cb6d31d986737fe3303d97dabcf94 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Tue, 30 Dec 2025 22:24:12 +0800 Subject: notif and scheduler changes --- backend/main.py | 21 ++++++++++++++++++--- backend/notif.py | 9 ++------- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'backend') diff --git a/backend/main.py b/backend/main.py index 10dd0a1..5f460e4 100644 --- a/backend/main.py +++ b/backend/main.py @@ -193,10 +193,19 @@ def reminder_timer_finished(timer_id): cursor.execute("SELECT * FROM timers WHERE timer_id = ?", (timer_id,)) out = cursor.fetchall() print(out) + + for row in out: + machine_status[row[RowIndices.BLOCK] - 1][row[RowIndices.MACHINE] - 1] = Status.FINISHED.name - #scheduler.add_job(final_timer_finished, 'date', run_date=out[0][RowIndices.END_TIME], id=str(timer_id), args=[timer_id]) + scheduler.add_job(final_timer_finished, 'date', run_date=out[0][RowIndices.END_TIME], id=str(timer_id), args=[timer_id]) - notif.send_notification(out[0][RowIndices.SUBSCRIPTION_ID]) + notif.send_notification( + out[0][RowIndices.SUBSCRIPTION_ID], + { + "title": "Laundry Reminder", + "body": "Your laundry is almost finished.", + } + ) def final_timer_finished(timer_id): print("timer finished!1", timer_id) @@ -206,7 +215,13 @@ def final_timer_finished(timer_id): for row in out: machine_status[row[RowIndices.BLOCK] - 1][row[RowIndices.MACHINE] - 1] = Status.FINISHED.name - notif.send_notification(out[0][RowIndices.SUBSCRIPTION_ID]) + notif.send_notification( + out[0][RowIndices.SUBSCRIPTION_ID], + { + "title": "Laundry Finished", + "body": "Do collect your laundry, then press this notification to mark your laundry as collected.", + } + ) # sec min hrs days COOKIE_MAX_AGE = 60 * 60 * 24 * 30 # 30 days diff --git a/backend/notif.py b/backend/notif.py index 57ccc23..46e7693 100644 --- a/backend/notif.py +++ b/backend/notif.py @@ -48,7 +48,7 @@ def subscribe(data: PushSubscriptionData): # --- send notification # ---- not used yet -def send_notification(endpoint: str): +def send_notification(endpoint: str, notification_payload: object): cursor.execute("SELECT * FROM subscriptions WHERE endpoint = ?", (endpoint,)) row = cursor.fetchall()[0] print(row) @@ -64,12 +64,7 @@ def send_notification(endpoint: str): try: webpush( subscription_info=subscription_info, - data=""" - { - "title": "Hello, world!", - "body": "Hello, Victoria Hall!" - } - """, + data=notification_payload, vapid_private_key=PRIVATE_VAPID_KEY, vapid_claims={ "sub": "mailto:dev@altafcreator.com", -- cgit v1.2.3