mirror of
https://github.com/Fare-spec/get_ovh_bills.git
synced 2025-12-07 10:20:36 +00:00
Add logging and doc
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from typing import Any, cast
|
||||
import ovh
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger("ovh_factures.fetcher")
|
||||
|
||||
|
||||
def fetch_api(app_key: str, app_secret: str, consumer_key: str) -> list[str]:
|
||||
@@ -12,12 +15,15 @@ def fetch_api(app_key: str, app_secret: str, consumer_key: str) -> list[str]:
|
||||
data: Any = client.get("/me/bill/")
|
||||
|
||||
if data is None:
|
||||
logger.warning("Réponse vide pour /me/bill/")
|
||||
return []
|
||||
|
||||
if not isinstance(data, list) or not all(isinstance(x, str) for x in data):
|
||||
logger.error("Réponse inattendue pour /me/bill/: %r", data)
|
||||
raise TypeError("Réponse OVH inattendue pour /me/bill/: liste de str requise")
|
||||
|
||||
bills: list[str] = cast(list[str], data)
|
||||
logger.info("%d factures détectées dans /me/bill/", len(bills))
|
||||
return bills
|
||||
|
||||
|
||||
@@ -32,5 +38,7 @@ def fetch_invoice_content(
|
||||
)
|
||||
bill = client.get(f"/me/bill/{id}")
|
||||
if bill is None:
|
||||
logger.error("Facture %s introuvable", id)
|
||||
raise RuntimeError(f"Facture {id} introuvable")
|
||||
logger.debug("Facture %s récupérée avec succès", id)
|
||||
return bill
|
||||
|
||||
Reference in New Issue
Block a user