tell if it is an update

This commit is contained in:
Stanislas Jouffroy 2025-05-23 16:40:29 +02:00
parent e34906ea14
commit 749865813f
7 changed files with 53 additions and 146 deletions

View file

@ -1,20 +1,33 @@
import datetime
from pathlib import Path
from menus import Menus
class ResultFile:
def __init__(self, path: Path):
self.path = path
def write(self, creation_date: str, modification_date: str, menu_type: str) -> None:
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"{creation_date}/{modification_date}/{menu_type}\n")
file.write(
f"{sha256} - {menus.days[0]} - {menus.month} - {datetime.date.today().year}\n"
)
def was_already_sent(
self, creation_date: str, modification_date: str, menu_type: str
):
def was_already_sent(self, sha256: str, menus: Menus):
if not self.path.exists():
return False
content = self.path.read_text()
return f"{creation_date}/{modification_date}/{menu_type}\n" in content
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}"
return f"{sha256} - {date}" not in content and date in content