Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/l_laval.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/l_laval.py : connecteur Le L Laval (l-laval.com)91# Projet locatif unique au 1585, boulevard des Laurentides, Laval (104 unités,92# studio à 5½). WordPress (thème maison) rendu serveur : la page93# /plans-condos-locatifs-laval/ contient un sélecteur d'étages avec UNE ligne94# <tr id="rowUnitNNN"> par unité — la classe « not-available » marque les95# unités louées, et l'attribut onclick=loadPage(unité, prix, pi², étage, état,96# typologie, sdb, salle d'eau, den, modulable) porte toutes les données.97# Granularité : unité. Certaines unités libres affichent 0$ (prix sur demande).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from ..schema import Listing, normalize_unit_type104from .base import BaseConnector105106BASE = "https://l-laval.com"107PLANS_URL = f"{BASE}/plans-condos-locatifs-laval/"108109ADDRESS = "1585, boulevard des Laurentides, Laval"110CITY = "Laval"111112# <tr id="rowUnit104" … class="ch1 not-available" … onclick='loadPage("104",…)'>113ROW_RE = re.compile(114 r'<tr\s+id="rowUnit(\w+)"[^>]*class="([^"]*)"[^>]*'115 r"onclick='loadPage\(([^)]*)\)'", re.I)116ARG_RE = re.compile(r'"([^"]*)"')117IMG_RE = re.compile(118 r"https://l-laval\.com/wp-content/uploads/[^\"'\s\\]+\.(?:jpe?g|png|webp)",119 re.I)120SKIP_IMG_RE = re.compile(r"logo|favicon|icon|plan|-\d{2,4}x\d{2,4}\.", re.I)121122123class LLavalConnector(BaseConnector):124 source_id = "l_laval"125 request_delay = 0.6126 max_images = 10127128 def _site_images(self) -> list[str]:129 """Photos du projet (page d'accueil) — les unités n'ont pas de galerie."""130 try:131 html = self.get(f"{BASE}/").text132 except Exception:133 return []134 return [u for u in dict.fromkeys(IMG_RE.findall(html))135 if not SKIP_IMG_RE.search(u)][: self.max_images]136137 def fetch(self) -> list[Listing]:138 html = self.get(PLANS_URL).text139 images = self._site_images()140141 listings: list[Listing] = []142 seen: set[str] = set()143 for unit, classes, raw_args in ROW_RE.findall(html):144 if "not-available" in classes or unit in seen:145 continue146 seen.add(unit)147 # loadPage(unité, prix, pi², étage, état, typologie, sdb, s. d'eau,148 # den, modulable) — état : 0 libre, 1 vendu, 2 réservé149 args = ARG_RE.findall(raw_args)150 if len(args) < 6:151 continue152 _, price_raw, sqft_raw, floor, etat, typo = args[:6]153 if etat.strip() not in ("", "0"):154 continue155 sdb = args[6] if len(args) > 6 else ""156 seau = args[7] if len(args) > 7 else ""157158 typo = typo.replace("½", "½").replace("1/2", "½")159 unit_type = normalize_unit_type(typo)160161 price = None162 price_label = ""163 m = re.search(r"(\d[\d\s,]*)\s*\$", price_raw)164 if m:165 try:166 val = float(m.group(1).replace(" ", "").replace(",", ""))167 if 300 <= val <= 20000:168 price = val169 price_label = price_raw.strip()170 except ValueError:171 pass172 if price is None:173 price_label = "Prix sur demande"174175 area = None176 try:177 v = float(sqft_raw)178 if 100 <= v <= 10000:179 area = v180 except ValueError:181 pass182183 desc_bits = [f"Unité {unit}, {floor}e étage" if floor else "",184 f"{sdb} salle(s) de bain" if sdb not in ("", "0") else "",185 "salle d'eau" if seau not in ("", "0") else ""]186 listings.append(Listing(187 source=self.source_id,188 external_id=unit,189 url=f"{PLANS_URL}#unite-{unit}",190 title=f"Le L Laval — Unité {unit}",191 address=ADDRESS,192 city=CITY,193 unit_type=unit_type,194 price=price,195 price_label=price_label,196 availability="Disponible",197 area_sqft=area,198 description=" — ".join(b for b in desc_bits if b),199 images=list(images),200 ))201 return listings202