Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/martin_roy.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/martin_roy.py : connecteur Construction Martin Roy91# (constructionmartinroy.com — Saint-Georges, Beauce). WordPress (WP Engine)92# rendu serveur : la page /logement-a-louer/ liste 18 fiches par adresse93# (cartes .v-logements-louer__logements-modeles-item) avec statut94# Loué/Disponible, prix ($/mois, « À partir de », « Sur demande »),95# chambres, salles de bain, superficie et photo (background-image).96# On n'ingère que les unités NON louées (statut ≠ Loué). Les pages détail97# /logement/<slug>/ sont derrière un WAF Cloudflare agressif : on s'en98# tient à la liste, qui contient déjà tous les champs utiles.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing, parse_price107from .base import BaseConnector108109BASE = "https://constructionmartinroy.com"110LIST_URL = f"{BASE}/logement-a-louer/"111112CITY = "Saint-Georges"113P = "v-logements-louer__logements-modeles-" # préfixe des classes du thème114115BG_IMG_RE = re.compile(r"url\((['\"]?)(https?://[^'\")]+)\1\)", re.I)116AREA_RE = re.compile(r"(\d[\d\s]{2,5})\s*pi", re.I)117PHONE_RE = re.compile(r"(\d{3})[\s.\-](\d{3})[\s.\-](\d{4})")118119120class MartinRoyConnector(BaseConnector):121 source_id = "martin_roy"122 request_delay = 0.6123124 def fetch(self) -> list[Listing]:125 listings: list[Listing] = []126 html = self.get(LIST_URL).text127 soup = BeautifulSoup(html, "html.parser")128129 # téléphone du promoteur (lien tel: global du site)130 details_common: dict = {}131 tel = soup.select_one('a[href^="tel:"]')132 if tel:133 digits = re.sub(r"\D", "", tel.get("href", ""))[-10:]134 if len(digits) == 10:135 details_common["contact"] = {"phone": "-".join(136 (digits[:3], digits[3:6], digits[6:]))}137138 for item in soup.select(f"li.{P}item"):139 try:140 statut_el = item.select_one(f".{P}statut")141 statut = statut_el.get_text(strip=True) if statut_el else ""142 # on n'ingère que les unités encore offertes143 if re.search(r"lou[ée]", statut, re.I):144 continue145146 a = item.select_one(f"a.{P}lien")147 if not a or not a.get("href"):148 continue149 url = a["href"].split("?")[0]150 slug = url.rstrip("/").split("/")[-1]151 if not slug:152 continue153154 titre_el = item.select_one(f".{P}image-titre")155 street = titre_el.get_text(strip=True) if titre_el else slug156 address = street if re.search(r"saint-georges", street, re.I) \157 else f"{street}, Saint-Georges"158159 prix_el = item.select_one(f".{P}contenu-prix")160 price_label = re.sub(r"\s+", " ", prix_el.get_text(161 " ", strip=True)) if prix_el else ""162 price = parse_price(price_label) \163 if "demande" not in price_label.lower() else None164165 def _num(cls: str) -> float | None:166 el = item.select_one(f".{P}contenu-{cls} span")167 v = el.get_text(strip=True) if el else ""168 return float(v) if re.fullmatch(r"\d+(\.\d+)?", v) else None169170 bedrooms = _num("chambre")171 bathrooms = _num("salle-bain")172 area = None173 sup_el = item.select_one(f".{P}contenu-superficie span")174 sup = sup_el.get_text(strip=True) if sup_el else ""175 am = AREA_RE.search(sup)176 if am:177 val = float(am.group(1).replace(" ", ""))178 if 200 <= val <= 3000: # le site affiche parfois le lot179 area = val180181 images: list[str] = []182 bg = BG_IMG_RE.search(a.get("style") or "")183 if bg:184 images.append(bg.group(2))185186 listings.append(Listing(187 source=self.source_id,188 external_id=slug,189 url=url,190 title=address,191 address=address,192 city=CITY,193 bedrooms=bedrooms,194 bathrooms=bathrooms,195 price=price,196 price_label=price_label if "$" in price_label else "",197 availability=statut or "Disponible",198 area_sqft=area,199 details=dict(details_common),200 images=images,201 ))202 except Exception:203 continue204 return listings205