From ad7e3e5b1ff85979a4b9cbbc544a178fb1fc51d2 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Mon, 18 May 2026 12:16:03 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9cup=C3=A9ration=20de=20sch=C3=A9ma=20plu?= =?UTF-8?q?s=20robuste=20et=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .template.env | 9 +++++---- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- src/utils/data.py | 29 ++++++++++++++++++++--------- uv.lock | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.template.env b/.template.env index 6ac9a91..98967e9 100644 --- a/.template.env +++ b/.template.env @@ -9,16 +9,17 @@ ANNOUNCEMENTS= # Chemin vers le schéma de données DATA_SCHEMA_PATH=https://www.data.gouv.fr/api/1/datasets/r/9a4144c0-ee44-4dec-bee5-bbef38191d9a +DATA_SCHEMA_PATH_LOCAL=../schema.json # Colonnes masquées par défaut DISPLAYED_COLUMNS="uid, acheteur_id, acheteur_nom, montant, objet, titulaire_nom, titulaire_id, dateNotification, dureeMois, acheteur_departement_code, sourceDataset" # Formulaire de contact SENDER_SERVER_DOMAIN="mail.example.com" # serveur SMTP -LOGIN_PASSWORD="" # mot de passe du serveur -LOGIN_EMAIL="connect@example.fr" # adresse utilisée pour se connecter au serveur SMTP -FROM_EMAIL="from@example.com" # adresse d'envoi des emails (From) -TO_EMAIL="to@example.com" # adresse de destination des emails (To) +LOGIN_PASSWORD="" # mot de passe du serveur +LOGIN_EMAIL="connect@example.fr" # adresse utilisée pour se connecter au serveur SMTP +FROM_EMAIL="from@example.com" # adresse d'envoi des emails (From) +TO_EMAIL="to@example.com" # adresse de destination des emails (To) # Matomo MATOMO_ID_SITE= diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d5dbcd..6f96906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +##### 2.7.8 (18 mai 2026) + +- Récupération du schéma de données plus robuste, ne pas dépendre de data.gouv.fr + ##### 2.7.7 (11 mai 2026) - Suppression des mentions sur les profils d'acheteur. Omnikles/Safetender publie via l'API DUME et Klekoon ne publie pas, mais c'est peut-être pas le seul, donc je préfère supprimer et refaire un tour. diff --git a/pyproject.toml b/pyproject.toml index a1e0f52..362752d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "decp.info" description = "Interface d'exploration et d'analyse des marchés publics français." -version = "2.7.7" +version = "2.7.8" requires-python = ">= 3.10" authors = [{ name = "Colin Maudry", email = "colin@colmo.tech" }] dependencies = [ diff --git a/src/utils/data.py b/src/utils/data.py index eb9c170..0c792a5 100644 --- a/src/utils/data.py +++ b/src/utils/data.py @@ -2,7 +2,9 @@ import json import logging import os from collections import OrderedDict +from pathlib import Path +import httpx import polars as pl from httpx import HTTPError, get @@ -63,16 +65,25 @@ def get_departement_region(code_postal): def get_data_schema() -> dict: # Récupération du schéma des données tabulaires - path = os.getenv("DATA_SCHEMA_PATH") - if path.startswith("http"): - original_schema: dict = get( - os.getenv("DATA_SCHEMA_PATH"), follow_redirects=True - ).json() - elif os.path.exists(path): - with open(path) as f: + url = os.getenv("DATA_SCHEMA_PATH") + local_path = Path(os.getenv("DATA_SCHEMA_LOCAL", "")) + + original_schema = {} + if url: + try: + original_schema: dict = get(url, follow_redirects=True).json() + except ( + httpx.ReadTimeout, + httpx.ReadError, + httpx.ConnectError, + httpx.ConnectTimeout, + ): + logger.error(f"Erreur HTTP lors de la récupération du schéma ({url})") + + if os.path.exists(local_path) and original_schema == {}: + with open(local_path) as f: original_schema: dict = json.load(f) - else: - raise Exception(f"Chemin vers le schéma invalide: {path}") + logger.info(f"Utilisation du schéma local ({local_path})") new_schema = OrderedDict() diff --git a/uv.lock b/uv.lock index 9ac4ecc..0742454 100644 --- a/uv.lock +++ b/uv.lock @@ -760,7 +760,7 @@ wheels = [ [[package]] name = "decp-info" -version = "2.7.6" +version = "2.7.7" source = { virtual = "." } dependencies = [ { name = "dash", extra = ["compress"] },