Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/bati5.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/bati5.py : connecteur Bâti5 — Boisés Dion (www.bati5.ca)91# Condos locatifs neufs (sixplex) au 7150, rue Jean-Claude-Langlois,92# Boisbriand (quartier Boisés Dion). Zoho Sites rendu SERVEUR : la page93# d'accueil contient des cartes typologie « n½ [+ bureau] (niveau X) …94# à partir de NNNN $ [PROMO* $] … 1 unité disponible pour … » ou95# « Tous loués… ». On ignore les segments « masqué: … » (contenu caché par96# l'éditeur) et on NE GARDE que les typologies avec « n unité(s)97# disponible(s) ». Granularité : TYPOLOGIE (prix « à partir de »).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import html as _html102import re103104from ..schema import Listing105106from .base import BaseConnector107108BASE = "https://www.bati5.ca"109110ADDRESS = "7150, rue Jean-Claude-Langlois, Boisbriand"111CITY = "Boisbriand"112113# « 5½ + bureau (niveau RDC) 3 CHAMBRES + BUREAU + 2 SALLES DE BAIN114# à partir de 2560 $ 2450* $ 1 unité disponible pour 1 er mai 2026 »115CARD_RE = re.compile(116 r"(\d)\s*½\s*(\+\s*bureau)?\s*\(niveau\s*([^)]*)\)\s*" # typo, bureau, niv.117 r"(.{0,200}?)à\s*partir\s*de\s*(\d[\d\s]*)\s*\$" # desc, prix118 r"(?:\s*(\d[\d\s]*)\*\s*\$)?" # prix promo*119 r"(.{0,260}?)" # queue (dispo)120 r"(?=\d\s*½\s*(?:\+\s*bureau\s*)?\(niveau|Demander une visite|$)", re.S)121MASQUE_RE = re.compile(r"masqué\s*:\s*.*?(?=Tous lou|Demander|$)", re.S | re.I)122AVAIL_RE = re.compile(123 r"\d+\s*unités?\s*disponibles?[^.]{0,60}?(?:\d{4}|$)", re.I)124IMG_RE = re.compile(125 r"https://www\.bati5\.ca/files/[^\"'\s\\]+\.(?:jpe?g|png|webp)", re.I)126SKIP_IMG_RE = re.compile(r"logo|favicon|icon|bati5-01|_\d{2,4}x\d{2,4}\.", re.I)127128129class Bati5Connector(BaseConnector):130 source_id = "bati5"131 request_delay = 0.6132 max_images = 10133134 def fetch(self) -> list[Listing]:135 raw = self.get(f"{BASE}/").text136 images = [u for u in dict.fromkeys(IMG_RE.findall(raw))137 if not SKIP_IMG_RE.search(u)][: self.max_images]138139 text = _html.unescape(raw)140 text = re.sub(r"<script.*?</script>", " ", text, flags=re.S)141 text = re.sub(r"<style.*?</style>", " ", text, flags=re.S)142 text = re.sub(r"<[^>]+>", " ", text)143 text = re.sub(r"\s+", " ", text)144145 listings: list[Listing] = []146 seen: set[str] = set()147 for n, bureau, niveau, desc, price_raw, promo_raw, tail \148 in CARD_RE.findall(text):149 tail = MASQUE_RE.sub(" ", tail)150 m = AVAIL_RE.search(tail)151 if m is None: # « Tous loués… » -> on saute152 continue153 availability = re.sub(r"\b(\d+)\s*er\b", r"\1er",154 re.sub(r"\s+", " ", m.group(0))).strip()155156 unit_type = f"{n}½"157 variant = "bureau" if bureau else niveau.strip().lower() or "std"158 ext_id = f"bati5-{n}.5-{re.sub(r'[^a-z0-9]+', '-', variant)}"159 if ext_id in seen:160 continue161 seen.add(ext_id)162163 price = None164 amount = (promo_raw or price_raw).replace(" ", "").replace(" ", "")165 try:166 v = float(amount)167 if 300 <= v <= 20000:168 price = v169 except ValueError:170 pass171 label_bits = [f"à partir de {price_raw.strip()}$"]172 if promo_raw:173 label_bits.append(f"{promo_raw.strip()}$ en promotion")174175 beds = None176 m = re.search(r"(\d)\s*chambres?", desc, re.I)177 if m:178 beds = float(m.group(1))179180 title = f"Bâti5 — Boisés Dion — {unit_type}" \181 + (" + bureau" if bureau else "") \182 + (f" (niveau {niveau.strip()})" if niveau.strip() else "")183 listings.append(Listing(184 source=self.source_id,185 external_id=ext_id,186 url=f"{BASE}/",187 title=title,188 address=ADDRESS,189 city=CITY,190 unit_type=unit_type,191 bedrooms=beds,192 price=price,193 price_label=" — ".join(label_bits),194 availability=availability,195 description=re.sub(r"\s+", " ", desc).strip().capitalize(),196 images=list(images),197 ))198 return listings199