Browse Source

add messages for subscription loop

test-message
Trent Larson 9 months ago
parent
commit
561b04c678
  1. 7
      app.py
  2. 5
      webpush.py

7
app.py

@ -153,7 +153,7 @@ class WebPushService():
return True
except WebPushException as ex:
print(f"Failed to send push notification: {ex}")
print(f"Failed to send push notification for {subscription_info['endpoint']} -- {ex}")
return False
@ -176,6 +176,9 @@ class WebPushService():
while True:
now = datetime.datetime.now().isoformat()
print(f"{now} - Starting to send subscriptions...")
# Creating a context for the application to enable database operations
with self.app.app_context():
@ -186,7 +189,6 @@ class WebPushService():
vapid_key = VAPIDKey.query.first()
# Constructing the push notification message
now = datetime.datetime.now().isoformat()
message = {"title": "Daily Update", "message": f"Update for {now}"}
# Sending a push notification to each subscribed client
@ -199,6 +201,7 @@ class WebPushService():
}
}
WebPushService._send_push_notification(subscription_info, message, vapid_key)
print(f"{now} - Finished sending {len(all_subscriptions)} subscriptions.")
# Sleeping for 24 hours before sending the next set of notifications
time.sleep(24 * 60 * 60)

5
webpush.py

@ -1,6 +1,9 @@
# Test subscription creation
# Test subscription message
#
# Setup with `pip install -r requirements.txt` and then `source venv/bin/activate`
#
# Usage: python webpush.py "ENDPOINT|P256DH|AUTH" PRIVATE_KEY
# ... where, yes, that second arg includes the "|" character, matching sqlite output.
from pywebpush import webpush, WebPushException

Loading…
Cancel
Save