mirror of
https://github.com/Fare-spec/get_ovh_bills.git
synced 2025-12-07 10:20:36 +00:00
quick fixes
This commit is contained in:
14
main.py
14
main.py
@@ -140,7 +140,8 @@ def indexer(ids: list[str]) -> list[str]:
|
||||
"""
|
||||
conn = get_conn()
|
||||
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:
|
||||
ids_already_in = os.listdir(target_dir)
|
||||
except FileNotFoundError:
|
||||
@@ -168,7 +169,7 @@ def indexer(ids: list[str]) -> list[str]:
|
||||
send_error_mail(traceback.format_exc())
|
||||
continue
|
||||
bill_year = datetime.fromisoformat(meta["date"]).year
|
||||
if bill_year == YEAR:
|
||||
if bill_year == YEAR: # todo 1 januray case
|
||||
result.append(bill_id)
|
||||
else:
|
||||
not_valid_year.append((bill_id, bill_year))
|
||||
@@ -223,13 +224,12 @@ def save_pdf(bill: dict) -> None:
|
||||
Télécharge le PDF d’une facture dans un sous-dossier par année.
|
||||
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"]
|
||||
dest = f"{path}{bill['billId']}.pdf"
|
||||
try:
|
||||
urlretrieve(url, 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__":
|
||||
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())
|
||||
bills_json = []
|
||||
|
||||
Reference in New Issue
Block a user