Python 67%
TypeScript 18.2%
CSS 14.4%
1#!/usr/bin/env python32# -----------------------------------------------------------------------------3# House-Ka — fusion des candidats RealtyPress reste-du-Canada (2026-08-27)4# scripts/merge_canada_candidates.py : lit /tmp/rp_canada_candidates.json5# (sortie du scout), filtre (volume, Québec/Ontario), et ajoute les nouveaux6# sites à data/canada_agencies.json + data/sources.json.7# Usage : .venv/bin/python scripts/merge_canada_candidates.py [--min-cards 10]8# -----------------------------------------------------------------------------9import json10import re11import sys12from pathlib import Path1314ROOT = Path(__file__).resolve().parent.parent15CANDIDATES = Path("/tmp/rp_canada_candidates.json")16MIN_CARDS = int(sys.argv[sys.argv.index("--min-cards") + 1]) if "--min-cards" in sys.argv else 101718cands = json.loads(CANDIDATES.read_text())19reg_p = ROOT / "data" / "canada_agencies.json"20src_p = ROOT / "data" / "sources.json"21registry = json.loads(reg_p.read_text())22sources = json.loads(src_p.read_text())23known_domains = {re.sub(r"^https?://(www\.)?", "", e["site"]).rstrip("/")24 for e in registry}25known_ids = {s["id"] for s in sources["sources"]}2627added = []28for c in sorted(cands, key=lambda x: -x.get("approx_volume_gte", 0)):29 dom = c["domain"]30 if dom in known_domains:31 continue32 provs = c.get("provinces", {})33 total = sum(provs.values()) or 134 # province dominante observée sur la page 135 top = max(provs, key=provs.get) if provs else c.get("province_hint", "")36 # hors périmètre : sites majoritairement québécois ou ontariens (l'Ontario37 # est déjà couvert par les 15 sources existantes — n'ajouter que si gros)38 if re.search(r"qu[ée]bec", top, re.I):39 continue40 if top == "Ontario" and c.get("approx_volume_gte", 0) < 5000:41 continue42 if c.get("cards_page1", 0) < MIN_CARDS:43 continue44 slug = re.sub(r"[^a-z0-9]+", "", dom.split(".")[0])[:24]45 sid = f"rp_ag_{slug}"46 if sid in known_ids:47 continue48 pages = max(10, min(1500, c.get("approx_pages_gte", 1) * 2))49 entry = {50 "id": sid,51 "name": f"{dom} ({top or 'Canada'})",52 "site": f"https://{dom}",53 "archive": c.get("archive", "listing"),54 "max_pages": pages,55 "province": top or "Ontario",56 "note": (f"Recensement CANADA 2026-08-27 : ~≥{c.get('approx_volume_gte', '?')} fiches, "57 f"provinces page 1 : {provs}. RealtyPress/DDF."),58 }59 registry.append(entry)60 sources["sources"].append({61 "id": sid,62 "name": entry["name"],63 "url": entry["site"],64 "listing_url": f"{entry['site']}/{entry['archive']}/",65 "coverage": f"{top or 'Canada'} — ~≥{c.get('approx_volume_gte', '?')} fiches DDF",66 "connector": "realtypress",67 "status": "actif",68 "type": "agence",69 "note": "House-Ka — generic RealtyPress connector (registry data/canada_agencies.json). WordPress RealtyPress plugin on the CREA DDF feed. external_id ddf<id>: cross-site dedup by MIN(uid).",70 })71 known_ids.add(sid)72 known_domains.add(dom)73 added.append((sid, top, c.get("approx_volume_gte")))7475reg_p.write_text(json.dumps(registry, ensure_ascii=False, indent=1))76src_p.write_text(json.dumps(sources, ensure_ascii=False, indent=2))77print(f"{len(added)} nouvelles sources :")78for sid, top, vol in added:79 print(f" {sid:34s} {top:24s} ~≥{vol}")80