summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2025-12-30 22:24:12 +0800
committeraltaf-creator <dev@altafcreator.com>2025-12-30 22:24:12 +0800
commit90d97ee89e8cb6d31d986737fe3303d97dabcf94 (patch)
treeca6d56712841d584dadbe1d600b195946245380b
parent69b977a1ce9dcbce36b56c7ff3707d9ad1cfb07a (diff)
notif and scheduler changes
-rw-r--r--backend/main.py21
-rw-r--r--backend/notif.py9
2 files changed, 20 insertions, 10 deletions
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",