SPB Git

spb/qc-influenceurs Public

InfluenceursQC — classement des influenceurs du Québec.

JavaScript 83.3% Python 16.7%
1.1 KB · 27 lines python
Raw Blame History
1#!/usr/bin/env python32"""Fusionne data/dossiers_extracted/batch_*.json -> app/dossiers.json (clé = nom exact)."""3import glob4import json5import os67BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))8out = {}9total_facts = total_news = dated = 010for f in sorted(glob.glob(os.path.join(BASE, "data", "dossiers_extracted", "batch_*.json"))):11    try:12        d = json.load(open(f))13    except Exception as e:14        print(f"ERREUR {f}: {e}")15        continue16    for name, entry in d.items():17        facts = [x for x in (entry.get("facts") or []) if x.get("text")]18        news = [x for x in (entry.get("news") or []) if x.get("title") and x.get("url")]19        out[name] = {"facts": facts, "news": news}20        total_facts += len(facts)21        total_news += len(news)22        dated += sum(1 for x in facts if x.get("date"))23    print(f"{os.path.basename(f)}: {len(d)} personnes")2425json.dump(out, open(os.path.join(BASE, "app", "dossiers.json"), "w"), ensure_ascii=False)26print(f"\nTOTAL: {len(out)} personnes · {total_facts} faits ({dated} datés) · {total_news} actualités")27