diff options
author | meltland <[email protected]> | 2025-03-09 21:53:46 -0400 |
---|---|---|
committer | meltland <[email protected]> | 2025-03-09 21:53:46 -0400 |
commit | 0f93b0be310d3b60fa18f9d97fac5e8afebff6a6 (patch) | |
tree | 0d0999e4343119e0505bf19d027b4578f68a0f08 /db.py | |
parent | 5d72b3d54d336aa485dbf925855f1a6aaaa40f85 (diff) |
posting and some others
Diffstat (limited to 'db.py')
-rw-r--r-- | db.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/db.py b/db.py index 88dc79b..6750e47 100644 --- a/db.py +++ b/db.py @@ -94,4 +94,46 @@ class acc: user = usersd.find_one({"username": username}) if not user: return "notExists" - return user["permissions"] \ No newline at end of file + return user["permissions"] + +class posts: + def get_recent(amount=75): + posts = list(postsd.find().sort("created", -1).limit(amount)) + for i in posts: + data = acc.get(i["author"]) + if type(data) != dict: + data = {} + else: + del data["secure"] + del data["profile"] + i["author"] = data + incr = -1 + for j in i["replies"]: + incr += 1 + data = acc.get(j["author"]) + if type(data) != dict: + data = {} + else: + del data["secure"] + del data["profile"] + i["replies"][incr]["author"] = data + return posts + + def get_by_id(post_id): + post = postsd.find_one({"_id": post_id}) + if not post: + return "notExists" + else: + return post + + def add(data): + try: + postsd.insert_one(data) + except Exception as e: + return "fail" + return True + +class inbox: + def get_recent(amount=75): + posts = list(inboxd.find().sort("created", -1).limit(amount)) + return posts \ No newline at end of file |