Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/forum_mtl.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-2513# Last Modified : 2026-08-2514#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# Lou-Ka — Agrégateur de logements à louer (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# connectors/forum_mtl.py : Le Forum / Forum Properties (forumproperties.com) —91# promoteur avec immeubles locatifs au Québec : Berson Apartments (Plateau,92# Montréal), Lustra Ph. 1 (Terrebonne), 100 Windsor (Westmount).93# Techno : widget Planpoint — l'index résidentiel passe par l'endpoint94# POST app.planpoint.io/api/enterprises/find {namespace, hostName} qui95# renvoie {projects:[...]} avec floors[].units[] inline. On réutilise le96# helper partagé _planpoint.unit_listing pour le mapping unité -> Listing.97# Portefeuille pancanadien : on ne garde que les projets au Québec98# (adresse « , QC » ou lat/lng dans la province).99# Granularité : UNITÉ (« Available » ; prix publié sur Lustra seulement).100# -----------------------------------------------------------------------------101from __future__ import annotations102103import time104105from .base import BaseConnector106from ._planpoint import PLANPOINT_API, unit_listing107from ..schema import Listing108109NAMESPACE = "forum-residential-enterprise"110HOST_NAME = "forum-residential"111FALLBACK_URL = "https://www.forumproperties.com/fr/residentiel/"112113# adresses manquantes chez Planpoint (clé = namespace du projet)114_ADDRESS_FIX = {115 "100-1-windsor": "100 avenue Windsor, Westmount",116}117118119def _in_quebec(project: dict) -> bool:120 addr = (project.get("address") or "")121 if ", QC" in addr or ", Qc" in addr or "Québec" in addr:122 return True123 lat, lon = project.get("lat"), project.get("lon")124 if isinstance(lat, (int, float)) and isinstance(lon, (int, float)):125 return 44.5 <= lat <= 63.0 and -80.0 <= lon <= -56.0126 return False127128129class ForumMtlConnector(BaseConnector):130 """Forum Properties — unités Planpoint des immeubles québécois."""131132 source_id = "forum_mtl"133 request_delay = 1.0134 use_detail_cache = False # tout est inline dans enterprises/find135136 def _enterprise_projects(self) -> list[dict]:137 """POST /api/enterprises/find -> projets (floors/units inline)."""138 wait = self.request_delay - (time.time() - self._last_request)139 if wait > 0:140 time.sleep(wait)141 resp = self.session.post(f"{PLANPOINT_API}/enterprises/find",142 json={"namespace": NAMESPACE,143 "hostName": HOST_NAME},144 timeout=self.timeout)145 self._last_request = time.time()146 resp.raise_for_status()147 return resp.json().get("projects") or []148149 def fetch(self) -> list[Listing]:150 out: list[Listing] = []151 seen: set[str] = set()152 for project in self._enterprise_projects():153 if not _in_quebec(project):154 continue # AB/BC : hors périmètre Lou-Ka155 ns = project.get("namespace") or ""156 if not (project.get("address") or "").strip() and ns in _ADDRESS_FIX:157 project["address"] = _ADDRESS_FIX[ns]158 urls = project.get("internalURLs") or {}159 page_url = (urls.get("fr") or urls.get("en")160 or project.get("websiteURL")161 or project.get("internalURL") or FALLBACK_URL).strip()162 for floor in project.get("floors") or []:163 for unit in floor.get("units") or []:164 lst = unit_listing(self.source_id, project, floor, unit,165 page_url=page_url,166 default_city="Montréal")167 if lst and lst.external_id not in seen:168 seen.add(lst.external_id)169 out.append(lst)170 return out171