#!/usr/bin/env python3 """Fusionne data/dossiers_extracted/batch_*.json -> app/dossiers.json (clé = nom exact).""" import glob import json import os BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) out = {} total_facts = total_news = dated = 0 for f in sorted(glob.glob(os.path.join(BASE, "data", "dossiers_extracted", "batch_*.json"))): try: d = json.load(open(f)) except Exception as e: print(f"ERREUR {f}: {e}") continue for name, entry in d.items(): facts = [x for x in (entry.get("facts") or []) if x.get("text")] news = [x for x in (entry.get("news") or []) if x.get("title") and x.get("url")] out[name] = {"facts": facts, "news": news} total_facts += len(facts) total_news += len(news) dated += sum(1 for x in facts if x.get("date")) print(f"{os.path.basename(f)}: {len(d)} personnes") json.dump(out, open(os.path.join(BASE, "app", "dossiers.json"), "w"), ensure_ascii=False) print(f"\nTOTAL: {len(out)} personnes · {total_facts} faits ({dated} datés) · {total_news} actualités")