Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/majestic.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0913# Last Modified : 2026-08-0914#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/majestic.py : connecteur Le Majestic du Lac Boivin91# (majesticlacboivin.ca) — 1 complexe de condos locatifs haut de gamme à92# Granby (150 rue de la Lobélie, adresse affichée sur la page « Nous93# joindre », schema.org PostalAddress). Site custom (non-WordPress) : la94# page /fr/condos-locatifs.html rend côté serveur la liste des unités95# libres (div.uniteItem[data-id] dans .listeResultatUnite) avec unité,96# étage, chambres, salles de bain, superficie, loyer, disponibilité, plan97# PDF et bouton « Info » — les unités réservées portent span.nonDispo98# (« Réservé ») et sont écartées. Les inclusions/avantages de l'immeuble99# (listes .services-liste) complètent les commodités. external_id =100# data-id de l'unité (identifiant interne stable). Le loyer est parfois101# affiché sans « $ » (« 1795 ») : la colonne étant explicitement « Loyer »,102# le montant est extrait tel quel. robots.txt : /inc/, /Gestion/ et /auto/103# interdits — la page des condos est permise.104# -----------------------------------------------------------------------------105from __future__ import annotations106107import re108109from bs4 import BeautifulSoup110111from ..schema import Listing112from .base import BaseConnector113114BASE = "https://www.majesticlacboivin.ca"115LIST_URL = f"{BASE}/fr/condos-locatifs.html"116117# adresse du complexe, telle qu'affichée sur /fr/nous-joindre.html118ADDRESS = "150 rue de la Lobélie"119CITY = "Granby"120121122def _col_value(item, label: str) -> str:123 """Valeur d'une colonne uniteItemCol dont le titre est `label`."""124 for col in item.select(".uniteItemCol"):125 t = col.select_one(".uniteItemTitre")126 if t and t.get_text(" ", strip=True).lower() == label.lower():127 val = col.get_text(" ", strip=True)128 val = re.sub(re.escape(t.get_text(" ", strip=True)), "", val,129 count=1).strip()130 val = re.sub(r"\s+", " ", val)131 return re.sub(r"\bpi\s*2\b", "pi²", val) # « 735 pi<sup>2</sup> »132 return ""133134135class MajesticConnector(BaseConnector):136 source_id = "majestic"137 request_delay = 0.7138139 def fetch(self) -> list[Listing]:140 html = self.get(LIST_URL).text141 soup = BeautifulSoup(html, "html.parser")142143 # inclusions et avantages de l'immeuble (commodités communes)144 building_amenities: list[str] = []145 for ul in soup.select("ul.services-liste"):146 for li in ul.select("li.services-liste_item"):147 t = re.sub(r"\s+", " ", li.get_text(" ", strip=True)).strip()148 if t and t not in building_amenities:149 building_amenities.append(t)150151 listings: list[Listing] = []152 for item in soup.select(".listeResultatUnite .uniteItem[data-id]"):153 try:154 lst = self._parse_unit(item, building_amenities)155 except Exception:156 continue157 if lst and lst.external_id not in {l.external_id for l in listings}:158 listings.append(lst)159 return listings160161 def _parse_unit(self, item, building_amenities: list[str]) -> Listing | None:162 # unités réservées : bouton remplacé par span.nonDispo « Réservé »163 if item.select_one(".nonDispo"):164 return None165 ext_id = str(item.get("data-id") or "").strip()166 if not ext_id:167 return None168169 # « Unité 308 » : première colonne, sans titre170 unit_no = ""171 first = item.select_one(".uniteItemCol.c2 .uniteItemValeur")172 if first:173 unit_no = re.sub(r"\s+", " ", first.get_text(" ", strip=True)).strip()174175 etage = _col_value(item, "Étage")176 chambres = _col_value(item, "Chambres")177 sdb = _col_value(item, "Salles de bain")178 superficie = _col_value(item, "Superficie") # « 735 pi 2 »179 loyer = _col_value(item, "Loyer") # « 1695 $ » / « 1795 »180 dispo = _col_value(item, "Disponibilité")181 dispo = re.sub(r"\b(\d+)\s+(er|re|e)\b", r"\1\2", dispo) # « 1 er » -> « 1er »182183 # colonne « Loyer » explicite : montant extrait même sans « $ »184 price = None185 m = re.search(r"(\d[\d\s]{2,7})", loyer.replace(",", " "))186 if m:187 try:188 val = float(m.group(1).replace(" ", ""))189 if 100 <= val <= 20000:190 price = val191 except ValueError:192 pass193194 amenities = []195 for label, val in [("Chambres", chambres), ("Salle(s) de bain", sdb),196 ("Superficie", superficie), ("Étage", etage)]:197 if val:198 amenities.append(f"{label} : {val}")199 amenities += [a for a in building_amenities if a not in amenities]200201 area = None202 m_area = re.search(r"(\d{3,5})\s*pi", superficie)203 if m_area:204 area = float(m_area.group(1))205206 plan = item.select_one("a.planPDF[href]")207 details = {}208 if plan:209 details["plan_pdf"] = f"{BASE}/{plan['href'].lstrip('/')}"210211 title = f"Le Majestic du Lac Boivin — {unit_no}" if unit_no \212 else "Le Majestic du Lac Boivin"213 return Listing(214 source=self.source_id,215 external_id=ext_id,216 url=LIST_URL,217 title=title,218 address=ADDRESS,219 city=CITY,220 price=price,221 price_label=loyer,222 availability=dispo,223 area_sqft=area,224 amenities=amenities[:25],225 details=details,226 )227