Browse Source

add more logging

master
Trent Larson 9 months ago
parent
commit
b53d7a5e0d
  1. 6
      app.py
  2. 5
      webpush.py

6
app.py

@ -226,7 +226,8 @@ class WebPushService():
"auth": subscription.auth "auth": subscription.auth
} }
} }
WebPushService._send_push_notification(subscription_info, message, vapid_key) result = WebPushService._send_push_notification(subscription_info, message, vapid_key)
print(f"Result from sub {subscription.id}: success={result['success']} text={result['message']}", flush=True)
print(f"{now} - Finished sending {len(all_subscriptions)} subscriptions.", flush=True) print(f"{now} - Finished sending {len(all_subscriptions)} subscriptions.", flush=True)
# Sleeping for 24 hours before sending the next set of notifications # Sleeping for 24 hours before sending the next set of notifications
@ -470,8 +471,11 @@ class WebPushService():
{"title": title, "message": message}, {"title": title, "message": message},
vapid_key vapid_key
) )
print(f"Test sent: {result['success']}")
return jsonify(success=result["success"], message=result["message"]) return jsonify(success=result["success"], message=result["message"])
else: else:
print(f"Test failed due to missing subscription. Request: {json.dumps(content)}")
return jsonify({"success": False, "message": "Subscription not found"}), 404 return jsonify({"success": False, "message": "Subscription not found"}), 404

5
webpush.py

@ -75,13 +75,14 @@ if len(sys.argv) > 2:
try: try:
#print(str(subscription_info)) #print(str(subscription_info))
#sys.exit(0) #sys.exit(0)
result = webpush( response = webpush(
subscription_info, subscription_info,
data, data,
vapid_private_key=private_key_base64, vapid_private_key=private_key_base64,
vapid_claims={"sub": "mailto:info@timesafari.app"} vapid_claims={"sub": "mailto:info@timesafari.app"}
) )
print(f"Result from remote service: {result}") print(f"Response: {response}")
print(f"Full response: {response.__dict__}")
# log the .reason from Apple # log the .reason from Apple
# https://developer.apple.com/documentation/usernotifications/sending_web_push_notifications_in_web_apps_and_browsers#3994594 # https://developer.apple.com/documentation/usernotifications/sending_web_push_notifications_in_web_apps_and_browsers#3994594
except WebPushException as ex: except WebPushException as ex:

Loading…
Cancel
Save