-result:request.Responsehttps://requests.readthedocs.io/en/latest/api.html#requests.Response if the push notification was sent successfully
orFalseiftherewasanexception
orFalseiftherewasanexception
Notes:
Notes:
@ -205,41 +208,108 @@ class WebPushService():
whileTrue:
whileTrue:
now=datetime.datetime.now().isoformat()
now=datetime.datetime.now()
print(f"{now} - Starting to send subscriptions...",flush=True)
print(f"{now} - Starting to send subscriptions...",flush=True)
# Creating a context for the application to enable database operations
# Creating a context for the application to enable database operations
withself.app.app_context():
withself.app.app_context():
# Retrieving all subscription data from the database
# Retrieve the VAPID key from the database
all_subscriptions=Subscription.query.all()
# Retrieving the VAPID key from the database
vapid_key=VAPIDKey.query.first()
vapid_key=VAPIDKey.query.first()
# Constructing the push notification message
# Construct the push notification message
# The title value is a key, triggering the device to apply logic and customize both title and message.
# The title value is a key, triggering the device to apply logic and customize both title and message.
# See https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/src/commit/1e6159869fc28ca6e6b5b3d186617d75705100b4/sw_scripts/additional-scripts.js#L65
# See https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/src/commit/1e6159869fc28ca6e6b5b3d186617d75705100b4/sw_scripts/additional-scripts.js#L65
UPDATE_TITLE="DAILY_CHECK"
UPDATE_TITLE="DAILY_CHECK"
message={"title":UPDATE_TITLE,"message":f"Update for {now}"}
message={"title":UPDATE_TITLE,"message":f"Update for {now}"}
# Sending a push notification to each subscribed client
# Determine the beginning and end time to check for subscriptions
forsubscriptioninall_subscriptions:
settings=Settings.query.first()
subscription_info={
ifsettings.running_notify_end_timeisNone:
"endpoint":subscription.endpoint,
"keys":{
# set all subscriptions without a time to the current time
"p256dh":subscription.p256dh,
# (these won't be picked-up in the current run, since thie current minute is the end minute)