import datetime from pathlib import Path from menus import Menus class ResultFile: def __init__(self, path: Path): self.path = path def write(self, sha256: str, menus: Menus) -> None: if not self.path.exists(): self.path.write_text("") with self.path.open(mode="a") as file: file.write( f"{sha256} - {menus.days[0]} - {menus.month} - {datetime.date.today().year}\n" ) def was_already_sent(self, sha256: str, menus: Menus): if not self.path.exists(): return False content = self.path.read_text() return ( f"{sha256} - {menus.days[0]} - {menus.month} - {datetime.date.today().year}" in content ) def is_update(self, sha256: str, menus: Menus): if not self.path.exists(): return False content = self.path.read_text() date = f"{menus.days[0]} - {menus.month} - {datetime.date.today().year}" res = f"{sha256} - {date}" not in content and date in content if res: self.write(sha256, menus) return res