Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Immo·Ka9# File : immoka/connectors/pmml.py10# Module : immoka11# Repository : https://git.spboucher.ai/immo-ka12# Created : 2026-08-2313# Last Modified : 2026-08-2314#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/pmml.py : PMML (pmml.ca) — LA grande agence commerciale/91# multilogements indépendante du Québec (plex, multis, terrains, industriel,92# bureaux — ~550 inscriptions actives, toutes régions).93#94# Le site est une SPA (Svelte + Mapbox) derrière Cloudflare, mais son API95# JSON interne est ouverte : GET /api/proprietes/avendre?limit=1000 retourne96# TOUT l'inventaire à vendre en un appel (prix demandé, GPS, adresse civique,97# ville/région, unités rés./comm., superficies, année, courtier inscripteur,98# slug de fiche, photo principale). La chaîne anti-bot de BaseConnector99# (Oxylabs → Scrapfly → Bright Data) encaisse le 403 Cloudflare du direct.100# Pas de description dans le flux → on synthétise ≥3 caractéristiques101# structurées (unités, superficie, prix/logement…) pour la publication.102#103# IDPropriete est interne (pas de n° Centris exposé) → pas d'infixe _ag_ ;104# la dédup par adresse (inter-sources) couvre les recoupements éventuels.105# -----------------------------------------------------------------------------106from __future__ import annotations107108import json109import re110111from .base import BaseConnector112from ..schema import PropertyListing113114API = "https://pmml.ca/api/proprietes/avendre?limit=1000"115SITE = "https://pmml.ca"116AGENCY = "PMML"117118_TYPES = {119 "multilogement": "Multilogement", "terrain": "Terrain",120 "commerceDetail": "Commerce de détail", "industriel": "Industriel",121 "bureaux": "Bureaux", "rpa": "Résidence pour aînés (RPA)",122 "hotel": "Hôtel", "commercialGeneral": "Commercial",123 "fondCommerce": "Fonds de commerce",124 "portfolioRes": "Portefeuille résidentiel",125 "portfolioComm": "Portefeuille commercial",126}127_YEAR_RE = re.compile(r"\b(1[6-9]\d{2}|20\d{2})\b")128129130def _fmt_money(v) -> str:131 return f"{int(round(float(v))):,} $".replace(",", " ")132133134class PmmlConnector(BaseConnector):135 source_id = "pmml"136137 def fetch(self) -> list[PropertyListing]:138 rows = self.get(API).json()139 out: list[PropertyListing] = []140 for r in rows:141 if r.get("iLocation") or (r.get("sType") or "vente") != "vente":142 continue143 lid = r.get("IDPropriete")144 slug = r.get("slugFr") or ""145 if not lid or not slug:146 continue147 ptype = _TYPES.get(r.get("IDType") or "", r.get("IDType") or "")148 civic, street = (r.get("sNumeroCivique") or "").strip(), (r.get("sRue") or "").strip()149 address = f"{civic}, {street}".strip(", ") if street else ""150 city = (r.get("sNomVille") or "").strip()151152 price = r.get("fPrixDemande") if not r.get("iMasquerPrix") else None153 price_label = (_fmt_money(price) if price154 else (r.get("TextePourPrixFr") or "Prix sur demande"))155156 year = None157 ym = _YEAR_RE.search(str(r.get("iAnneeConstruction") or ""))158 if ym:159 year = int(ym.group(1))160161 # caractéristiques synthétiques (le flux n'a pas de description) :162 # ≥3 items = seuil de publication du module qualité163 features: list[str] = [ptype] if ptype else []164 details: dict = {"Type de propriété": ptype} if ptype else {}165 if r.get("iUnitesTotal"):166 features.append(f"{r['iUnitesTotal']} unités")167 details["Nombre d'unités"] = str(r["iUnitesTotal"])168 if r.get("iUnitesResidentiel"):169 details["Unités résidentielles"] = str(r["iUnitesResidentiel"])170 if r.get("iUnitesCommercial"):171 details["Unités commerciales"] = str(r["iUnitesCommercial"])172 if r.get("iAnneeConstruction"):173 features.append(f"Construction {r['iAnneeConstruction']}")174 details["Année de construction"] = str(r["iAnneeConstruction"])175 if r.get("iPiedsCarreTotal"):176 features.append(f"{r['iPiedsCarreTotal']:,} pi² (bâtiment)".replace(",", " "))177 details["Superficie du bâtiment"] = f"{r['iPiedsCarreTotal']:,} pi²".replace(",", " ")178 if r.get("iPiedsCarreTerrain"):179 features.append(f"{r['iPiedsCarreTerrain']:,} pi² (terrain)".replace(",", " "))180 details["Superficie du terrain"] = f"{r['iPiedsCarreTerrain']:,} pi²".replace(",", " ")181 if r.get("fCPL") and price:182 try:183 details["Prix par logement"] = _fmt_money(r["fCPL"])184 features.append(f"{_fmt_money(r['fCPL'])} / logement")185 except (TypeError, ValueError):186 pass187 if r.get("sNomSecteur"):188 details["Secteur PMML"] = r["sNomSecteur"]189 if r.get("plusTaxes"):190 details["Prix"] = "Plus taxes"191 if r.get("NoteApresPrixFr"):192 details["Note sur le prix"] = r["NoteApresPrixFr"]193194 broker = (r.get("sNomInscripteur") or "").strip()195 if r.get("sNomCoInscripteur"):196 broker = f"{broker} et {r['sNomCoInscripteur']}".strip(" et")197198 images = []199 try:200 images = [u for u in json.loads(r.get("Photos") or "[]") if u]201 except ValueError:202 pass203 if not images and r.get("sImagePrincipale"):204 images = [r["sImagePrincipale"]]205206 title = (r.get("TitreAltFr") or "").strip() or \207 f"{ptype or 'Propriété'} à vendre — {address or city}".strip(" —")208209 out.append(PropertyListing(210 source=self.source_id, external_id=str(lid),211 url=SITE + slug, title=title,212 address=address, city=city,213 region=(r.get("sNomRegion") or "").strip(),214 property_type=ptype, price=price, price_label=price_label,215 year_built=year,216 area_sqft=r.get("iPiedsCarreTotal"),217 lot_sqft=r.get("iPiedsCarreTerrain"),218 features=features, details=details, images=images,219 lat=r.get("dPosLat"), lng=r.get("dPosLong"),220 agency=AGENCY, broker_name=broker or AGENCY,221 ))222 return out223