Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : Immo·Ka10# File : scripts/refresh_via_capitale.py11# Module : scripts12# Repository : https://git.spboucher.ai/immo-ka13# Created : 2026-08-1214# Last Modified : 2026-08-1215#16# =============================================================================17# AUTHOR & PROFESSIONAL AFFILIATION18# =============================================================================19#20# Author : Simon-Pierre Boucher21# Position : Professor of Finance22# Institution : Université du Québec en Outaouais (UQO)23# Department : Département des sciences administratives24# Organization : SP Boucher25#26# Website : https://spboucher.ai27# Git : https://git.spboucher.ai28#29# =============================================================================30# OFFICIAL CONTACT DIRECTORY31# =============================================================================32#33# General : info@spboucher.ai34# Professional : contact@spboucher.ai35# Direct : simon@spboucher.ai36# Research : research@spboucher.ai37# Development : dev@spboucher.ai38# Support : support@spboucher.ai39# Security/Admin : admin@spboucher.ai40# Notifications : notifications@spboucher.ai41#42# Preferred Contact: contact@spboucher.ai43#44# =============================================================================45# COPYRIGHT & INTELLECTUAL PROPERTY46# =============================================================================47#48# Copyright (c) 202649# Simon-Pierre Boucher50#51# All rights reserved where applicable.52#53# This file is governed by the applicable project license,54# copyright notices, institutional agreements and relevant law.55#56# Unless expressly authorized by the applicable license or57# rights holder, copying, redistribution, sublicensing,58# publication and commercial exploitation are not permitted.59#60# Existing third-party rights and notices remain unaffected.61#62# =============================================================================63# CONFIDENTIALITY & SECURITY64# =============================================================================65#66# Classification : Public67# Distribution : Public repository; use is governed by the project license68# Security Contact : admin@spboucher.ai69#70# Access to this source does not independently grant permission71# to redistribute or disclose confidential materials.72#73# Do not embed credentials, private keys, access tokens,74# certificates or confidential personal information.75#76# =============================================================================77# LICENSE & MAINTENANCE78# =============================================================================79#80# License : None specified (no license file in this repository)81# Maintainer : Simon-Pierre Boucher82# Technical Contact: dev@spboucher.ai83#84# =============================================================================85# END OF SP BOUCHER SOURCE HEADER86# =============================================================================8788# -----------------------------------------------------------------------------89# Immo-Ka — régénère data/via_capitale_agencies.json en sondant les domaines90# des sous-agences Via Capitale (plateforme source.immo). Étend facilement la91# couverture : ajoute des bannières/domaines à CANDIDATES et relance.92# Usage : .venv/bin/python scripts/refresh_via_capitale.py93# -----------------------------------------------------------------------------94from __future__ import annotations9596import json97import re98import urllib.request99from pathlib import Path100101UA = {"User-Agent": "Mozilla/5.0 Chrome/126"}102CFG = "/wp-content/uploads/_sourceimmo/_configs.json"103OUT = Path(__file__).resolve().parent.parent / "data" / "via_capitale_agencies.json"104105# Domaines connus + bannières à tester (viacapitale<x>.{immo,com,ca}).106KNOWN_DOMAINS = [107 "viacapitaleelite.immo", "viacapitaleselect.com",108 "viacapitaledumontroyal.com", "viacapitaleacces.com",109 "viacapitalepartenaires.com",110]111BANNERS = [112 "elite", "select", "dumontroyal", "acces", "horizon", "diamant", "expertise",113 "cite", "vendu", "action", "distinction", "premium", "platine", "signature",114 "prestige", "excellence", "sommet", "boreal", "alliance", "synergie", "expert",115 "optima", "concept", "capitale", "3000", "2000", "or", "plus", "inter",116]117TLDS = [".immo", ".com", ".ca"]118119120def fetch_cfg(domain: str) -> dict | None:121 for host in (domain, f"www.{domain}"):122 try:123 b = urllib.request.urlopen(124 urllib.request.Request(f"https://{host}{CFG}", headers=UA), timeout=12125 ).read().decode("utf-8", "ignore")126 d = json.loads(b)127 if d.get("account_id") and d.get("api_key") and d.get("default_view"):128 return {"domain": host, "cfg": d}129 except Exception:130 continue131 return None132133134def main() -> None:135 domains = set(KNOWN_DOMAINS)136 for b in BANNERS:137 for t in TLDS:138 domains.add(f"viacapitale{b}{t}")139 reg, seen = [], set()140 for dom in sorted(domains):141 r = fetch_cfg(dom)142 if not r or r["domain"] in seen:143 continue144 seen.add(r["domain"])145 d = r["cfg"]146 banner = re.sub(r"^www\.viacapitale|\.(immo|com|ca)$", "", r["domain"])147 reg.append({148 "banner": banner, "domain": r["domain"],149 "account": d["account_id"], "api": d["api_key"],150 "app": d["app_id"], "view": d["default_view"],151 })152 print(f"OK {banner:16} {r['domain']}")153 OUT.write_text(json.dumps(reg, ensure_ascii=False, indent=1), encoding="utf-8")154 print(f"→ {len(reg)} sous-agences écrites dans {OUT}")155156157if __name__ == "__main__":158 main()159