diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/main.py | 15 | ||||
| -rw-r--r-- | backend/notif_test.py | 21 |
2 files changed, 33 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;") diff --git a/backend/notif_test.py b/backend/notif_test.py new file mode 100644 index 0000000..e0d82c0 --- /dev/null +++ b/backend/notif_test.py @@ -0,0 +1,21 @@ +from dotenv import load_dotenv +from os import getenv +import onesignal +from onesignal.api import default_api +from onesignal.model.notification import Notification + +load_dotenv() + +onesignal_configuration = onesignal.Configuration( + rest_api_key=getenv("REST_API_KEY"), + organization_api_key=getenv("ORGANIZATION_API_KEY"), +) + +api_client = onesignal.ApiClient(onesignal_configuration) +api_instance = default_api.DefaultApi(api_client) + +ONESIGNAL_APP_ID = "83901cc7-d964-475a-90ec-9f854df4ba52" + +# yes that's my subscription id. probably outdated by now +notification = Notification(app_id=ONESIGNAL_APP_ID, include_subscription_ids=['86f24e73-8887-4e29-b607-31e1a8f25b93', '6a2b4b58-a1d2-403b-afa0-b4a987ca6139'], contents={'en': 'hello world'}, headings={'en': 'Laundry Finished!'}, priority=10) +print(api_instance.create_notification(notification)) |
