fix(misc): store processed post IDs as strings

This commit is contained in:
2026-07-29 18:29:02 +05:00
parent 9478f7d793
commit 8ddfef70d4
+7 -7
View File
@@ -4,29 +4,29 @@ from typing import Set, List
class ProcessedPostsManager: class ProcessedPostsManager:
def __init__(self, file_path: str = "processed.txt"): def __init__(self, file_path: str = "processed.txt"):
self.file_path = file_path self.file_path = file_path
self.processed_posts: Set[int] = self._load() self.processed_posts: Set[str] = self._load()
def _load(self) -> Set[int]: def _load(self) -> Set[str]:
try: try:
with open(self.file_path, "r", encoding="utf-8") as processed: with open(self.file_path, "r", encoding="utf-8") as processed:
return set(processed.readlines()) return {line.strip() for line in processed if line.strip()}
except: except:
return set() return set()
def _save(self): def _save(self):
with open(self.file_path, "w", encoding="utf-8") as processed: with open(self.file_path, "w", encoding="utf-8") as processed:
processed.writelines(lines=self.processed_posts) processed.write("\n".join(self.processed_posts))
def is_processed(self, post_id: int) -> bool: def is_processed(self, post_id: int) -> bool:
return post_id in self.processed_posts return str(post_id) in self.processed_posts
def mark_processed(self, post_id: int): def mark_processed(self, post_id: int):
self.processed_posts.add(post_id) self.processed_posts.add(str(post_id))
self._save() self._save()
def add_existing_posts(self, post_ids: List[int]): def add_existing_posts(self, post_ids: List[int]):
for post_id in post_ids: for post_id in post_ids:
self.processed_posts.add(post_id) self.processed_posts.add(str(post_id))
self._save() self._save()