Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Immo·Ka9# File : immoka/connectors/century21_agences.py10# Module : immoka11# Repository : https://git.spboucher.ai/immo-ka12# Created : 2026-08-1213# Last Modified : 2026-08-1214#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author : Simon-Pierre Boucher20# Position : Professor of Finance21# Institution : Université du Québec en Outaouais (UQO)22# Department : Département des sciences administratives23# Organization : SP Boucher24#25# Website : https://spboucher.ai26# Git : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General : info@spboucher.ai33# Professional : contact@spboucher.ai34# Direct : simon@spboucher.ai35# Research : research@spboucher.ai36# Development : dev@spboucher.ai37# Support : support@spboucher.ai38# Security/Admin : admin@spboucher.ai39# Notifications : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification : Public66# Distribution : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License : None specified (no license file in this repository)80# Maintainer : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687# -----------------------------------------------------------------------------88# Immo-Ka — Agrégateur de maisons à vendre (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# connectors/century21_agences.py : Century 21 par SOUS-AGENCES (robuste)91#92# Le portail central c21.ca délègue à une iframe moxiworks verrouillée93# (503/WAF, même via Firecrawl). Mais les bureaux Century 21 du Québec tournent94# sur la plateforme source.immo (ID-3 Technologies) : quebec.c21.ca,95# excel.c21.ca et century21immoplus.com partagent un même compte96# « Century 21 - All Quebec » (inventaire provincial complet), et97# vision.c21.ca a son propre compte. L'API publique (api-v1.source.immo)98# est paginée par st/nt (voir sourceimmo.py) — inventaire complet accessible.99#100# Une classe par sous-agence est générée depuis data/century21_agencies.json101# (source_id « c21_ag_<slug> »). Le n° Centris sert de clé de déduplication102# (voir web.py, sources « %_ag_% ») — aucun double-comptage entre les skins103# partageant le même compte ni avec le reste du site.104# -----------------------------------------------------------------------------105from __future__ import annotations106107import json108import re109from pathlib import Path110111from .sourceimmo import SourceImmoConnector112from ..schema import PropertyListing113114REGISTRY = Path(__file__).resolve().parent.parent.parent / "data" / "century21_agencies.json"115116117class Century21AgenceConnector(SourceImmoConnector):118 """Sous-agence Century 21 sur source.immo. Les sous-classes fournissent119 account_id / api_key / app_id / view_id / site_url / agency_name."""120121 agency_name = "Century 21"122123 def fetch(self) -> list[PropertyListing]:124 # auto-guérison : recharger les identifiants depuis la config publique125 # du site (résilient si source.immo fait tourner ses UUID).126 try:127 cfg = self.get(128 f"{self.site_url.rstrip('/')}/wp-content/uploads/_sourceimmo/_configs.json"129 ).json()130 self.account_id = cfg.get("account_id", self.account_id)131 self.api_key = cfg.get("api_key", self.api_key)132 self.app_id = cfg.get("app_id", self.app_id)133 self.view_id = cfg.get("default_view", self.view_id)134 except Exception:135 pass # on garde les valeurs du registre136 return super().fetch()137138 def _to_listing(self, it: dict) -> PropertyListing | None:139 lst = super()._to_listing(it)140 if lst is not None:141 lst.broker_name = self.agency_name142 ref = it.get("ref_number") or it.get("id")143 if ref and self.site_url:144 lst.url = f"{self.site_url.rstrip('/')}/propriete/{ref}"145 return lst146147148def _load() -> list[dict]:149 try:150 return json.loads(REGISTRY.read_text(encoding="utf-8"))151 except Exception:152 return []153154155def _slug(banner: str) -> str:156 return "c21_ag_" + re.sub(r"[^a-z0-9]+", "_", banner.lower()).strip("_")157158159for _ag in _load():160 if not all(_ag.get(k) for k in ("domain", "account", "api", "app", "view")):161 continue162 _sid = _slug(_ag["banner"])163 _name = "Century 21 " + _ag["banner"].replace("-", " ").title()164 globals()[_sid.upper()] = type(165 "".join(p.title() for p in _sid.split("_")),166 (Century21AgenceConnector,),167 {168 "source_id": _sid,169 "account_id": _ag["account"],170 "api_key": _ag["api"],171 "app_id": _ag["app"],172 "view_id": _ag["view"],173 "site_url": f"https://{_ag['domain']}",174 "agency_name": _name,175 },176 )177