From dcd93038fca3b9eb84be132891ec93f4d327b0b1 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Jul 2026 16:38:56 +0500 Subject: [PATCH] feat(misc): add ProcessedPostsManager utility --- misc.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 misc.py diff --git a/misc.py b/misc.py new file mode 100644 index 0000000..fb26ca6 --- /dev/null +++ b/misc.py @@ -0,0 +1,32 @@ +from typing import Set, List + + +class ProcessedPostsManager: + def __init__(self, file_path: str = "processed.txt"): + self.file_path = file_path + self.processed_posts: Set[int] = self._load() + + def _load(self) -> Set[int]: + try: + with open(self.file_path, "r", encoding="utf-8") as processed: + return set(processed.readlines()) + + except: + return set() + + def _save(self): + with open(self.file_path, "w", encoding="utf-8") as processed: + processed.writelines(lines=self.processed_posts) + + def is_processed(self, post_id: int) -> bool: + return post_id in self.processed_posts + + def mark_processed(self, post_id: int): + self.processed_posts.add(post_id) + self._save() + + def add_existing_posts(self, post_ids: List[int]): + for post_id in post_ids: + self.processed_posts.add(post_id) + + self._save()