SPB Git

Repository Public

agences_source_immo.py 7.1 KB 173 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Immo·Ka9# File             : immoka/connectors/agences_source_immo.py10# Module           : immoka11# Repository       : https://git.spboucher.ai/immo-ka12# Created          : 2026-08-1213# Last Modified    : 2026-08-2414#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/agences_source_immo.py : agences INDÉPENDANTES sur la plateforme91#   source.immo (plugin WordPress). Beaucoup de petites/moyennes agences QC92#   l'utilisent (liste sur source.immo). Chacune expose sa config publique à93#   /wp-content/uploads/_sourceimmo/_configs.json → on lit l'API publique94#   api-v1.source.immo (voir SourceImmoConnector). Ce sont des agences95#   autonomes : leurs inscriptions (leur propre n° Centris) sont ADDITIVES —96#   pas de sous-agence d'une bannière déjà couverte → source_id normal (pas _ag_).97#   EXCEPTION : les équipes/agences dont une partie des inscriptions est98#   co-listée avec une bannière couverte (co-inscription Centris) portent un id99#   « si_ag_<slug> » : la dédup Centris (db.refresh_dedup, sources %_ag_%)100#   masque leurs doublons tout en gardant leurs fiches uniques visibles.101#102#   Un connecteur par agence est généré depuis data/source_immo_agencies.json.103# -----------------------------------------------------------------------------104from __future__ import annotations105106import json107from pathlib import Path108109from .sourceimmo import SourceImmoConnector110from ..schema import PropertyListing111112REGISTRY = Path(__file__).resolve().parent.parent.parent / "data" / "source_immo_agencies.json"113114115class _AgenceSourceImmo(SourceImmoConnector):116    """Agence indépendante source.immo. Recharge sa config depuis le site117    (résilient aux rotations d'UUID) ; agency_name pour l'affichage Sources."""118119    agency_name = ""120    # segment d'URL des fiches sur le site WordPress (raccourci source.immo) —121    # certains thèmes utilisent autre chose que « propriete » (ex. BLVD :122    # « details-de-la-propriete ») ; surchargé via listing_path du registre.123    listing_path = "propriete"124125    def fetch(self) -> list[PropertyListing]:126        base = self.site_url.rstrip("/")127        try:128            cfg = self.get(f"{base}/wp-content/uploads/_sourceimmo/_configs.json").json()129            self.account_id = cfg.get("account_id", self.account_id)130            self.api_key = cfg.get("api_key", self.api_key)131            self.app_id = cfg.get("app_id", self.app_id)132            self.view_id = cfg.get("default_view", self.view_id)133        except Exception:134            pass135        return super().fetch()136137    def _to_listing(self, it: dict) -> PropertyListing | None:138        lst = super()._to_listing(it)139        if lst is not None:140            lst.broker_name = self.agency_name141            lst.agency = 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('/')}/{self.listing_path}/{ref}"145        return lst146147148def _load() -> list[dict]:149    try:150        return json.loads(REGISTRY.read_text(encoding="utf-8"))151    except Exception:152        return []153154155# Génère une classe par agence du registre.156for _ag in _load():157    if not all(_ag.get(k) for k in ("id", "domain", "account", "api", "app", "view")):158        continue159    _sid = _ag["id"]160    _dom = _ag["domain"].rstrip("/")161    globals()[f"AGENCE_{_sid.upper()}"] = type(162        "AgenceSI" + "".join(p.title() for p in _sid.split("_")),163        (_AgenceSourceImmo,),164        {165            "source_id": _sid,166            "account_id": _ag["account"], "api_key": _ag["api"],167            "app_id": _ag["app"], "view_id": _ag["view"],168            "site_url": f"https://{_dom}/",169            "agency_name": _ag.get("name", _sid.title()),170            "listing_path": _ag.get("listing_path", "propriete"),171        },172    )173
Files main
Menu

Theme