diff options
| author | altaf-creator <dev@altafcreator.com> | 2025-12-03 15:08:58 +0700 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2025-12-03 15:08:58 +0700 |
| commit | 2f946c233ee67e149b79c2878efeddbbb0dc1846 (patch) | |
| tree | 719ffc079275f9cff322c89bb08aa83826ceeb91 /backend/main.py | |
| parent | 3979b8bcb35bc981355a83134ce7828dbfc7c0e3 (diff) | |
notif
Diffstat (limited to 'backend/main.py')
| -rw-r--r-- | backend/main.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/backend/main.py b/backend/main.py index 22d2936..c69247f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -106,6 +106,7 @@ ONESIGNAL_APP_ID = "83901cc7-d964-475a-90ec-9f854df4ba52" class RequestData(BaseModel): duration: int machine_id: str + onesignal_subscription_id: str class InformationRequestData(BaseModel): @@ -191,7 +192,11 @@ def reminder_timer_finished(timer_id): scheduler.add_job(final_timer_finished, 'date', run_date=out[0][RowIndices.END_TIME], id=str(timer_id), args=[timer_id]) - notification = Notification(app_id=ONESIGNAL_APP_ID, included_segments=['All'], contents={'en': 'get ready to get your bloody laundry'}, headings={'en': 'laundry almost finished'}, priority=10) + notification = Notification(app_id=ONESIGNAL_APP_ID, + include_subscription_ids=[out[0][RowIndices.SUBSCRIPTION_ID]], + contents={'en': 'get ready to get your bloody laundry'}, + headings={'en': 'Laundry Reminder'}, + priority=10) try: api_response = api_instance.create_notification(notification) @@ -204,7 +209,11 @@ def final_timer_finished(timer_id): cursor.execute(f"SELECT * FROM timers WHERE timer_id = '{timer_id}'") out = cursor.fetchall() - notification = Notification(app_id=ONESIGNAL_APP_ID, included_segments=['All'], contents={'en': 'get your bloody laundry'}, headings={'en': 'laundry finished'}, priority=10) + notification = Notification(app_id=ONESIGNAL_APP_ID, + include_subscription_ids=[out[0][RowIndices.SUBSCRIPTION_ID]], + contents={'en': 'get your bloody laundry'}, + headings={'en': 'Laundry Finished'}, + priority=10) try: api_response = api_instance.create_notification(notification) @@ -276,7 +285,7 @@ def start_new_timer(data: RequestData, response: fastapi.Response, session_key: end_date = now + datetime.timedelta(minutes=(data.duration * 30)) cursor.execute(f""" INSERT INTO timers (user_id, start_time, end_time, block, machine, status, subscription_id) - VALUES ('{session_key}', '{now.isoformat()}', '{end_date.isoformat()}', {block}, {machine}, 'RUNNING', 'TODO') + VALUES ('{session_key}', '{now.isoformat()}', '{end_date.isoformat()}', {block}, {machine}, 'RUNNING', '{data.onesignal_subscription_id}') """) conn.commit() cursor.execute("SELECT * FROM timers;") |
