diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-09 08:59:52 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-09 08:59:52 +0300 |
| commit | 7e2a136db5921755a29fa5c9a1751028688c55cd (patch) | |
| tree | 372d972fe21cb25f6c441a994aa4db669c89010b /wsgi | |
| parent | d1b1c055bb9ed49530e9a96fd34b3ada5899bbb5 (diff) | |
| download | csca5028-7e2a136db5921755a29fa5c9a1751028688c55cd.tar.gz csca5028-7e2a136db5921755a29fa5c9a1751028688c55cd.zip | |
Add last_viewed handling
Diffstat (limited to 'wsgi')
| -rw-r--r-- | wsgi/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/wsgi/__init__.py b/wsgi/__init__.py index dab7b7e..9a504b0 100644 --- a/wsgi/__init__.py +++ b/wsgi/__init__.py @@ -1,3 +1,4 @@ +from datetime import datetime, UTC from typing import Any, Dict, List from components.database import subscriptions from components.subscriptions.main import Subscription @@ -38,3 +39,26 @@ def add_sub() -> Dict[str, Any]: ) sub.insert() return sub_info_from_dict(sub.asdict()) + +@app.post("/set-time-between-fetches/") +def set_time_between_fetches() -> Dict[str, Any]: + return {} + +@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) + result = subscriptions.update_one( + {"_id": request.form["_id"]}, + {"$set": {"last_viewed": viewed_time}} + ) + if not result.modified_count: + raise Exception("Subscription %s not found" % request.form["_id"]) + return { + "_id": request.form["_id"], + "last_viewed": viewed_time, + } |
