Files
Auto-Stars-Improved/modules/misc.py
T

33 lines
979 B
Python

from typing import Set, List
class ProcessedPostsManager:
def __init__(self, file_path: str = "processed.txt"):
self.file_path = file_path
self.processed_posts: Set[str] = self._load()
def _load(self) -> Set[str]:
try:
with open(self.file_path, "r", encoding="utf-8") as processed:
return {line.strip() for line in processed if line.strip()}
except:
return set()
def _save(self):
with open(self.file_path, "w", encoding="utf-8") as processed:
processed.write("\n".join(self.processed_posts))
def is_processed(self, post_id: int) -> bool:
return str(post_id) in self.processed_posts
def mark_processed(self, post_id: int):
self.processed_posts.add(str(post_id))
self._save()
def add_existing_posts(self, post_ids: List[int]):
for post_id in post_ids:
self.processed_posts.add(str(post_id))
self._save()