started the project

This commit is contained in:
2025-09-04 18:57:48 +02:00
parent 83e5156b15
commit 363e5cd8c0
2 changed files with 76 additions and 0 deletions

49
main.py Normal file
View File

@@ -0,0 +1,49 @@
import os
import dotenv
import ovh
import fetcher as ft
import datetime
from urllib.request import urlretrieve
dotenv.load_dotenv()
APP_KEY = os.getenv("APP_KEY")
APP_SECRET = os.getenv("APP_SECRET")
CONSUMER_KEY = os.getenv("CONSUMER_KEY")
def get_ids() -> list[str]:
try:
ids = ft.fetch_api(
app_key=APP_KEY,
app_secret=APP_SECRET,
consumer_key=CONSUMER_KEY,
)
return ids
except ovh.exceptions.APIError as e:
raise RuntimeError(f"Échec récupération IDs factures: {e}") from e
def get_bill(bill_id: str) -> dict:
try:
return ft.fetch_invoice_content(
bill_id,
app_key=APP_KEY,
app_secret=APP_SECRET,
consumer_key=CONSUMER_KEY,
)
except ovh.exceptions.APIError as e:
raise RuntimeError(f"Échec récupération facture {bill_id}: {e}") from e
def get_pdf(bill: dict):
url = bill["pdfUrl"]
date = f"{datetime.datetime.fromisoformat(bill['date']).date()}.pdf"
urlretrieve(url, date)
if __name__ == "__main__":
ids = get_ids()
print(ids)
if ids:
bill = get_bill(ids[0])
get_pdf(bill)