Browse Source

fix dict key references

master
Trent Larson 9 months ago
parent
commit
acb37a50c1
  1. 13
      app.py

13
app.py

@ -154,7 +154,7 @@ class WebPushService():
)
# "because sometimes that's what I had to do to make it work!" - Matthew
time.sleep(1)
return {"success": True, "message": result.text, "result": result}
return {"success": result["status_code"] == 201, "message": result.text, "result": result}
except WebPushException as ex:
now = datetime.datetime.now().isoformat()
@ -162,6 +162,7 @@ class WebPushService():
print(f"{now}: Failed to send push notification for {endpoint} -- {ex}", flush=True)
unsubscribed_msg = '410 Gone'
unsubscribed = False
if unsubscribed_msg in ex.args[0]:
subscription = Subscription.query.filter_by(endpoint=endpoint).first()
@ -170,12 +171,13 @@ class WebPushService():
db.session.delete(subscription)
db.session.commit()
print(f"Committed delete of {subscription_info}", flush=True)
unsubscribed = True
else:
print(f"Could not find subscription at: {endpoint}", flush=True)
else:
print("Error other than unsubscribed/expired.", ex.args[0], flush=True)
return {"success": False, "message": ex.args[0]}
return {"success": False, "message": ex.args[0], "error": ex, "unsubscribed": unsubscribed}
def _send_daily_notifications(self) -> None:
@ -367,7 +369,7 @@ class WebPushService():
result = WebPushService._send_push_notification(subscription_info, message, vapid_key)
# Returning the operation status
return jsonify(success=result["status_code"]==201, message=result["text"])
return jsonify(success=result["success"], message=result["message"])
@staticmethod
@ -464,10 +466,7 @@ class WebPushService():
{"title": title, "message": message},
vapid_key
)
return jsonify(
success=result["result"].status_code==201,
message=result["result"].text,
)
return jsonify(success=result["success"], message=result["message"])
else:
return jsonify({"success": False, "message": "Subscription not found"}), 404

Loading…
Cancel
Save