Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/loggia.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/loggia.py : connecteur Loggia Saint-Lambert (loggiasaintlambert.com)91# Trois immeubles locatifs (Loggia 1, 2, 3) sur l'avenue Saint-Charles à92# Saint-Lambert. WordPress rendu serveur : la page /le-projet/ embarque une93# carte interactive (blocs « div.available.bloc.appt-N-demi » libellés94# « 111-$2495. - 4 ½ / Disponible ») et ~260 fiches d'unités (« Appartement95# NNN / Loggia N / ÉTAGE N », p.dispo[.not] = Loué/Disponible/Réservé,96# p.superficie, plan PNG/PDF). On ne retient que les unités « Disponible ».97# Granularité : unité.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from .base import BaseConnector106from ..schema import Listing, normalize_unit_type107108BASE = "https://www.loggiasaintlambert.com"109PAGE_URL = f"{BASE}/le-projet/"110111CITY = "Saint-Lambert"112ADDRESS = "avenue Saint-Charles, Saint-Lambert"113114# « Appartement 111-$2495. » (prix parfois accolé au numéro)115TITLE_RE = re.compile(r"Appartement\s+(\d+)\s*(?:[-–]\s*\$\s*([\d\s, ]+))?",116 re.I)117# libellé de bloc carte : « 111-$2495. - 4 ½ »118BLOC_RE = re.compile(r"(\d+)\s*[-–]\s*\$\s*([\d\s, ]+)[.\s]*[-–]\s*"119 r"(\d\s*½|\d\s*1/2|studio)", re.I)120SQFT_RE = re.compile(r"([\d,\s ]+)\s*pi", re.I)121LOGGIA_RE = re.compile(r"Loggia\s*(\d)", re.I)122ETAGE_RE = re.compile(r"[ÉE]TAGE\s*(\d+)", re.I)123124125def _num(s: str) -> float | None:126 s = re.sub(r"[\s, ]", "", s or "")127 try:128 return float(s)129 except ValueError:130 return None131132133class LoggiaConnector(BaseConnector):134 source_id = "loggia"135 request_delay = 0.6136137 def fetch(self) -> list[Listing]:138 listings: list[Listing] = []139 try:140 html = self.get(PAGE_URL).text141 except Exception:142 return listings143 soup = BeautifulSoup(html, "html.parser")144145 # 1) typologie par unité via les blocs de la carte (disponibles seulement)146 # « 111-$2495. - 4 ½ » → {("<no>", "<prix>"): "4½"}147 types: dict[str, str] = {}148 for bloc in soup.select("div.available.bloc"):149 m = BLOC_RE.search(bloc.get_text(" ", strip=True))150 if m:151 types[m.group(1)] = normalize_unit_type(m.group(3))152153 # 2) fiches d'unités : on garde celles dont p.dispo = « Disponible »154 for p in soup.select("p.dispo"):155 try:156 if "not" in (p.get("class") or []):157 continue158 if "disponible" not in p.get_text(strip=True).lower():159 continue # « Réservé » etc.160 card = p.find_parent("div", class_="col-md-8")161 if not card:162 continue163 text = card.get_text(" ", strip=True)164 mt = TITLE_RE.search(text)165 if not mt:166 continue167 unit_no = mt.group(1)168 price = _num(mt.group(2)) if mt.group(2) else None169170 building = ""171 mb = LOGGIA_RE.search(text)172 if mb:173 building = f"Loggia {mb.group(1)}"174 floor = ""175 mf = ETAGE_RE.search(text)176 if mf:177 floor = f"Étage {mf.group(1)}"178179 sqft = None180 sp = card.select_one("p.superficie")181 if sp:182 ms = SQFT_RE.search(sp.get_text(strip=True))183 if ms:184 sqft = _num(ms.group(1))185186 images: list[str] = []187 for img in card.select("div.plan-unite img"):188 src = img.get("src") or ""189 if src.startswith("http"):190 images.append(src)191 details: dict = {}192 a = card.select_one('a[href*=".pdf"]')193 if a and a.get("href"):194 mp = re.search(r"(https://[^\s\"]+\.pdf)", a["href"])195 details["plan_pdf"] = mp.group(1) if mp else a["href"]196 if building:197 details["building"] = building198 if floor:199 details["floor"] = floor200201 unit_type = types.get(unit_no, "")202 bslug = building.lower().replace(" ", "") or "x"203 ext_id = f"{bslug}-{unit_no}"204 if any(l.external_id == ext_id for l in listings):205 continue206 listings.append(Listing(207 source=self.source_id,208 external_id=ext_id,209 url=PAGE_URL,210 title=f"Appartement {unit_no}"211 + (f" ({unit_type})" if unit_type else "")212 + (f" — {building}, Loggia Saint-Lambert" if building213 else " — Loggia Saint-Lambert"),214 address=ADDRESS,215 city=CITY,216 unit_type=unit_type,217 price=price,218 availability="Disponible",219 area_sqft=sqft,220 details=details,221 images=images[:15],222 ))223 except Exception:224 continue225 return listings226