Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/lsr.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/lsr.py : connecteur LSR GesDev (lsrgesdev.ca — anciennement91# lsrgesdev.com, redirige) — développeur-gestionnaire de Saint-Lambert.92# Le site corporatif ne publie aucun prix ; l'inventaire locatif vit sur93# lenovia.ca (WordPress) avec DEUX backends différents :94# - NOVIA centre-ville – Longueuil (300, place Charles-Le Moyne) : widget95# Livya (app.livya.com, client « lsr-gesdev », projet « novia ») — flux96# RSC Next.js parsé par la base commune LivyaConnector (_livya.py) ;97# - NOVIA de la Gare – Candiac (125, rue des Marronniers) : widget Planpoint98# (app.planpoint.io/125-marronniers/125-marronniers) — API JSON publique99# via le helper _planpoint.py.100# Granularité = UNITÉ pour les deux projets (prix, pi², chambres, étage).101# Roomî (espaceroomi.ca, résidence étudiante Trois-Rivières) exclu.102# -----------------------------------------------------------------------------103from __future__ import annotations104105import html as _html106import re107108from ..schema import Listing109from ._livya import LivyaConnector110from ._planpoint import planpoint_projects, unit_listing111112CANDIAC_PAGE = "https://lenovia.ca/novia-de-la-gare-candiac/plans/"113CANDIAC_NAMESPACE = "125-marronniers"114CANDIAC_HOST = "125-marronniers"115116# prix planchers par typologie publiés sur lenovia.ca (Livya n'expose aucun117# prix pour Longueuil) : « 3 ½ (de 541 pi2 à 769 pi2) à partir de 1 950$ /mois »118LONGUEUIL_APTS = "https://lenovia.ca/novia-centre-ville-longueuil/appartements/"119TYPE_TOKEN_RE = re.compile(r"Studio|\d\s*½|Maison de ville", re.I)120FROM_PRICE_RE = re.compile(121 r"à\s+partir\s+de\s+([\d\s ]{3,9})\$\s*/?\s*mois", re.I)122SCRIPT_RE = re.compile(r"<(script|style)[\s\S]*?</\1>", re.I)123TAG_RE = re.compile(r"<[^>]+>")124125126class LSRConnector(LivyaConnector):127 source_id = "lsr"128 request_delay = 0.8129130 # -- NOVIA centre-ville (Longueuil) via Livya --------------------------------131 client = "lsr-gesdev"132 brand = "NOVIA centre-ville"133 site_url = "https://www.lsrgesdev.ca"134 default_city = "Longueuil"135 default_projects = ["novia"]136137 def fetch(self) -> list[Listing]:138 listings = super().fetch() # Longueuil (Livya)139 floors = self._longueuil_floor_prices()140 for lst in listings:141 lst.city = re.sub(r"^Ville de\s+", "", lst.city or "")142 # Livya ne publie aucun loyer pour Longueuil : on rattache le prix143 # plancher « à partir de » publié par lenovia.ca pour la typologie144 if lst.price is None and not lst.price_label:145 base = floors.get(lst.unit_type)146 if base:147 lst.price_label = f"à partir de {int(base)} $ /mois"148 listings.extend(self._candiac()) # Candiac (Planpoint)149 return listings150151 def _longueuil_floor_prices(self) -> dict[str, float]:152 """{'3½': 1950.0, …} depuis la page publique « Appartements »."""153 try:154 html = self.get(LONGUEUIL_APTS).text155 except Exception:156 return {}157 flat = re.sub(r"[\s ]+", " ",158 TAG_RE.sub(" | ", _html.unescape(SCRIPT_RE.sub(" ", html))))159 # segment « typologie -> texte jusqu'à la typologie suivante » pour ne160 # jamais rattacher le prix d'un 3½ au Studio « Complet » qui le précède161 tokens = list(TYPE_TOKEN_RE.finditer(flat))162 prices: dict[str, float] = {}163 for i, tok in enumerate(tokens):164 end = tokens[i + 1].start() if i + 1 < len(tokens) else len(flat)165 seg = flat[tok.end():min(end, tok.end() + 200)]166 pm = FROM_PRICE_RE.search(seg)167 if not pm:168 continue169 label = re.sub(r"\s+", "", tok.group(0))170 key = "Studio" if label.lower() == "studio" else label171 if key.lower() == "maisondeville":172 continue # typologie non « n½ » : ignorée173 try:174 val = float(re.sub(r"[\s ]", "", pm.group(1)))175 except ValueError:176 continue177 if 500 <= val <= 8000:178 prices.setdefault(key, val)179 return prices180181 # -- NOVIA de la Gare (Candiac) via Planpoint --------------------------------182 def _candiac(self) -> list[Listing]:183 try:184 projects = planpoint_projects(self, "projects",185 CANDIAC_NAMESPACE, CANDIAC_HOST)186 except Exception:187 return []188 listings: list[Listing] = []189 for project in projects:190 for floor in project.get("floors") or []:191 for unit in floor.get("units") or []:192 lst = unit_listing(self.source_id, project, floor, unit,193 page_url=CANDIAC_PAGE,194 default_city="Candiac")195 if lst is not None:196 listings.append(lst)197 return listings198