Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/lok36.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/lok36.py : connecteur LOK 36 (lok36.com)91# Immeuble locatif au 36, boulevard de la Seigneurie Ouest, Blainville92# (60 unités, 3½ à 5½). WordPress rendu serveur : la page /prix-plans/93# contient une image cliquable dont chaque unité a un tooltip94# <div id="wl-tooltip-XXXX-N" class="wl-tooltip"> avec Modèle : TypeN,95# Numéro:NNN, Chambre(s) :4½, Superficie : NNN pi2, Prix : NNNN$,96# Statut : LOUÉ|Disponible et un lien plan PDF. On ne garde que les unités97# NON louées. Granularité : unité (external_id = numéro d'unité).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from ..schema import Listing, normalize_unit_type104105from .base import BaseConnector106107BASE = "https://www.lok36.com"108PLANS_URL = f"{BASE}/prix-plans/"109110ADDRESS = "36, boulevard de la Seigneurie Ouest, Blainville"111CITY = "Blainville"112113TOOLTIP_RE = re.compile(114 r'<div id="wl-tooltip-([\d-]+)" class="wl-tooltip">')115FIELD_RE = {116 "model": re.compile(r"Modèle\s*:\s*([^<\s][^<]*)"),117 "num": re.compile(r"Numéro\s*:\s*([\w-]+)"),118 "typo": re.compile(r"Chambre\(s\)\s*:\s*([^<]+)"),119 "area": re.compile(r"Superficie\s*:\s*(\d[\d\s]*)"),120 "price": re.compile(r"Prix\s*:\s*(\d[\d\s,]*)\s*\$"),121 "status": re.compile(122 r"Statut\s*:\s*(.+?)(?:\s*Télécharger|$)", re.I),123}124PDF_RE = re.compile(r'href="(https://www\.lok36\.com/[^"]+\.pdf)"')125IMG_RE = re.compile(126 r"https://www\.lok36\.com/wp-content/uploads/[^\"'\s\\]+"127 r"\.(?:jpe?g|png|webp)", re.I)128SKIP_IMG_RE = re.compile(r"logo|favicon|icon|plan|feuillet|-\d{2,4}x\d{2,4}\.",129 re.I)130131132class Lok36Connector(BaseConnector):133 source_id = "lok36"134 request_delay = 0.6135 max_images = 10136137 def _site_images(self) -> list[str]:138 """Photos du projet (page d'accueil) — les tooltips n'ont qu'un PDF."""139 try:140 html = self.get(f"{BASE}/").text141 except Exception:142 return []143 return [u for u in dict.fromkeys(IMG_RE.findall(html))144 if not SKIP_IMG_RE.search(u)][: self.max_images]145146 def fetch(self) -> list[Listing]:147 html = self.get(PLANS_URL).text148 images = self._site_images()149150 listings: list[Listing] = []151 seen: set[str] = set()152 parts = TOOLTIP_RE.split(html)153 for i in range(1, len(parts) - 1, 2):154 body = parts[i + 1]155 body = body.split("</div></div>")[0] # fin du tooltip156 text = re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", body))157158 fields = {k: (m.group(1).strip() if (m := rx.search(text)) else "")159 for k, rx in FIELD_RE.items()}160 num = fields["num"]161 if not num or num in seen:162 continue163 seen.add(num)164 if re.search(r"lou[ée]", fields["status"], re.I):165 continue # LOUÉ166167 unit_type = normalize_unit_type(fields["typo"])168169 price = None170 price_label = ""171 if fields["price"]:172 try:173 v = float(fields["price"].replace(" ", "")174 .replace(" ", "").replace(",", ""))175 if 300 <= v <= 20000:176 price = v177 price_label = f"{int(v)}$/mois"178 except ValueError:179 pass180181 area = None182 if fields["area"]:183 try:184 v = float(fields["area"].replace(" ", "").replace(" ", ""))185 if 100 <= v <= 10000:186 area = v187 except ValueError:188 pass189190 details: dict = {}191 m = PDF_RE.search(body)192 if m:193 details["floor_plan"] = m.group(1)194195 desc_bits = [f"Unité {num}",196 f"Modèle {fields['model']}" if fields["model"] else ""]197 listings.append(Listing(198 source=self.source_id,199 external_id=num,200 url=PLANS_URL,201 title=f"LOK 36 — Unité {num}",202 address=ADDRESS,203 city=CITY,204 unit_type=unit_type,205 price=price,206 price_label=price_label,207 availability=fields["status"] or "Disponible",208 area_sqft=area,209 description=" — ".join(b for b in desc_bits if b),210 details=details,211 images=list(images),212 ))213 return listings214