quick fixes

This commit is contained in:
2025-10-10 17:43:22 +02:00
parent a1bf4667b2
commit ced5247136

14
main.py
View File

@@ -140,7 +140,8 @@ def indexer(ids: list[str]) -> list[str]:
""" """
conn = get_conn() conn = get_conn()
logger.info("Indexation des factures pour l'année %s", YEAR) logger.info("Indexation des factures pour l'année %s", YEAR)
target_dir = f"{PATH_OVH}{YEAR}" target_dir = os.path.join(PATH_OVH, str(YEAR))
try: try:
ids_already_in = os.listdir(target_dir) ids_already_in = os.listdir(target_dir)
except FileNotFoundError: except FileNotFoundError:
@@ -168,7 +169,7 @@ def indexer(ids: list[str]) -> list[str]:
send_error_mail(traceback.format_exc()) send_error_mail(traceback.format_exc())
continue continue
bill_year = datetime.fromisoformat(meta["date"]).year bill_year = datetime.fromisoformat(meta["date"]).year
if bill_year == YEAR: if bill_year == YEAR: # todo 1 januray case
result.append(bill_id) result.append(bill_id)
else: else:
not_valid_year.append((bill_id, bill_year)) not_valid_year.append((bill_id, bill_year))
@@ -223,13 +224,12 @@ def save_pdf(bill: dict) -> None:
Télécharge le PDF dune facture dans un sous-dossier par année. Télécharge le PDF dune facture dans un sous-dossier par année.
Noms de fichiers : <billId>.pdf Noms de fichiers : <billId>.pdf
""" """
date = datetime.fromisoformat(bill["date"]).date()
path = f"{PATH_OVH}{date.year}/"
os.makedirs(path, exist_ok=True) year_dir = os.path.join(PATH_OVH, str(date.year))
os.makedirs(year_dir, exist_ok=True)
dest = os.path.join(year_dir, f"{bill['billId']}.pdf")
url = bill["pdfUrl"] url = bill["pdfUrl"]
dest = f"{path}{bill['billId']}.pdf"
try: try:
urlretrieve(url, dest) urlretrieve(url, dest)
logger.info("Facture %s sauvegardée dans %s", bill["billId"], dest) logger.info("Facture %s sauvegardée dans %s", bill["billId"], dest)
@@ -241,7 +241,7 @@ def save_pdf(bill: dict) -> None:
if __name__ == "__main__": if __name__ == "__main__":
logger.info("Démarrage du traitement des factures OVH pour %s", YEAR) logger.info("Démarrage du traitement des factures OVH pour %s", YEAR)
os.makedirs(f"{PATH_OVH}{YEAR}", exist_ok=True) os.makedirs(os.path.join(PATH_OVH, str(YEAR)), exist_ok=True)
ids_candidats = indexer(get_ids()) ids_candidats = indexer(get_ids())
bills_json = [] bills_json = []