From 9fb20553d9f9e21c012f730a728c33d368e09bf2 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Thu, 9 Oct 2025 09:51:14 +0300 Subject: Add methods to modify/delete subscriptions --- wsgi/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'wsgi') diff --git a/wsgi/__init__.py b/wsgi/__init__.py index 9a504b0..f8f59db 100644 --- a/wsgi/__init__.py +++ b/wsgi/__init__.py @@ -42,13 +42,29 @@ def add_sub() -> Dict[str, Any]: @app.post("/set-time-between-fetches/") def set_time_between_fetches() -> Dict[str, Any]: - return {} + time_between_fetches = int(request.form["time_between_fetches"]) + result = subscriptions.update_one( + {"_id": request.form["_id"]}, + {"$set": {"time_between_fetches": time_between_fetches}} + ) + if not result.modified_count: + raise Exception("Subscription %s not found" % request.form["_id"]) + return { + "_id": request.form["_id"], + "time_between_fetches": time_between_fetches, + } + +@app.delete("/delete-sub/") +def delete_sub(id: str) -> Dict[str, Any]: + result = subscriptions.delete_one({"_id": id}) + if not result.deleted_count: + raise Exception("Subscription %s not found" % id) + return { "_id": id, } @app.post("/set-viewed/") def set_viewed() -> Dict[str, Any]: viewed_time_str = request.form.get("viewed_time") if viewed_time_str: - print(viewed_time_str) viewed_time = datetime.fromisoformat(viewed_time_str) else: viewed_time = datetime.now(tz=UTC) -- cgit v1.2.3-70-g09d2