summaryrefslogtreecommitdiff
path: root/backend/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/main.py')
-rw-r--r--backend/main.py28
1 files changed, 4 insertions, 24 deletions
diff --git a/backend/main.py b/backend/main.py
index 7be9c75..4758149 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -194,37 +194,17 @@ 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,
- 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)
- except Exception as e:
- print(e)
-
+ notif.send_notification(out[0][RowIndices.SUBSCRIPTION_ID])
def final_timer_finished(timer_id):
print("timer finished!1", timer_id)
cursor.execute("SELECT * FROM timers WHERE timer_id = ?", (timer_id,))
out = cursor.fetchall()
- 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)
- except Exception as e:
- print(e)
-
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])
# sec min hrs days
COOKIE_MAX_AGE = 60 * 60 * 24 * 30 # 30 days
@@ -293,7 +273,7 @@ def start_new_timer(data: RequestData, response: fastapi.Response, session_key:
try:
print("session key valid", session_key)
- end_date = now + datetime.timedelta(minutes=(data.duration * 30))
+ end_date = now + datetime.timedelta(seconds=(data.duration * 30))
cursor.execute("""
INSERT INTO timers (user_id, start_time, end_time, block, machine, status, subscription_id)
VALUES (?, ?, ?, ?, ?, ?, ?)""", (session_key, now.isoformat() + TZ, end_date.isoformat() + TZ, block, machine, 'RUNNING', subscription_endpoint,))
@@ -313,7 +293,7 @@ def start_new_timer(data: RequestData, response: fastapi.Response, session_key:
return "something went wrong during sql stuff"
try:
- scheduler.add_job(reminder_timer_finished, 'date', run_date=end_date - datetime.timedelta(minutes=5), id=timer_id, args=[timer_id])
+ scheduler.add_job(reminder_timer_finished, 'date', run_date=end_date - datetime.timedelta(seconds=5), id=timer_id, args=[timer_id])
except Exception as exception:
print("err @ scheduler //", exception)
response.status_code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR