"""Chargement des configurations de scraping externalisées (sélecteurs YAML). Permet de réparer un site cassé en modifiant un fichier de config sans toucher au code. Chaque source peut avoir un fichier `configs/.yaml`. """ import logging from functools import lru_cache from typing import Any import yaml from app.config import get_settings logger = logging.getLogger(__name__) @lru_cache def load_scraper_config(source_name: str) -> dict[str, Any]: path = get_settings().scrapers_config_dir / f"{source_name}.yaml" if not path.exists(): logger.debug("Pas de config externe pour %s (%s)", source_name, path) return {} try: with path.open(encoding="utf-8") as fh: config = yaml.safe_load(fh) or {} logger.info("Config de scraping chargée pour %s", source_name) return config except yaml.YAMLError as exc: logger.error("Config %s invalide : %s", path, exc) return {}