Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/capital_rdr.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/capital_rdr.py : connecteur Gestion Capital RDR (gestionrdr.com)91# 545 appartements à Trois-Rivières / Cap-de-la-Madeleine (fusionnés dans la92# ville de Trois-Rivières). Site GoDaddy Website Builder : la page93# « Logements à louer » est un widget « menu » dont chaque item porte un94# data-aid stable (MENU_ITEM_<hash du titre>) avec titre (« 4½ au 43095# Saint-Maurice »), prix (« 990.00$ »), photo et description en paragraphes96# (« *Disponible immédiatement!* », adresse civique, inclusions, animaux…).97# Pas de fiche individuelle : l'URL renvoie à la page + ancre de l'item.98# robots.txt permissif (sitemap seulement).99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing107from .base import BaseConnector108109BASE = "https://gestionrdr.com"110LIST_URL = f"{BASE}/logements-%C3%A0-louer-1"111112# ligne d'adresse civique dans la description (« 430 rue St-Maurice App9 »)113_ADDR_RE = re.compile(114 r"^\d[\dA-Za-z\-]*\s+(?:rue|av(?:enue)?\.?|boul(?:evard)?\.?|bd|chemin|"115 r"ch\.|côte|place|route|rang|montée)\b.*", re.I)116# type d'unité au début du titre (« 4½ au 430 Saint-Maurice »)117_TYPE_RE = re.compile(r"^\s*(\d\s*(?:½|1/2)|studio|loft|chambre)", re.I)118119120class CapitalRDRConnector(BaseConnector):121 source_id = "capital_rdr"122 request_delay = 0.7123124 def fetch(self) -> list[Listing]:125 html = self.get(LIST_URL).text126 soup = BeautifulSoup(html, "html.parser")127128 listings: list[Listing] = []129 seen: set[str] = set()130 for item in soup.select('[data-aid^="MENU_ITEM_"]'):131 ext_id = item.get("data-aid", "")[len("MENU_ITEM_"):].strip()132 # MENU_ITEM_GRID_<n> = conteneur de grille, pas un item133 if not ext_id or ext_id.startswith("GRID") or ext_id in seen:134 continue135 seen.add(ext_id)136 title_el = item.select_one('[data-aid*="_TITLE"]')137 price_el = item.select_one('[data-aid*="_PRICE"]')138 desc_el = item.select_one('[data-aid*="_DESC"]')139 img_el = item.select_one('img[data-aid*="_IMAGE"]')140 title = title_el.get_text(" ", strip=True) if title_el else ""141 if not title:142 continue143 price_label = price_el.get_text(" ", strip=True) if price_el else ""144145 # description : paragraphes bruts du widget146 lines: list[str] = []147 if desc_el:148 for p in desc_el.find_all("p"):149 t = re.sub(r"\s+", " ", p.get_text(" ", strip=True))150 t = t.replace(" ", " ").strip()151 if t:152 lines.append(t)153154 # disponibilité : ligne « *Disponible …* » (texte source)155 availability = ""156 for t in lines:157 if re.search(r"disponible", t, re.I):158 availability = t.strip("*").strip()159 break160161 # adresse : ligne civique de la description, sinon partie du titre162 address = ""163 for t in lines:164 if _ADDR_RE.match(t):165 address = t166 break167 if not address:168 m = re.search(r"\bau\s+(\d.*)$", title)169 if m:170 address = m.group(1).strip()171172 m = _TYPE_RE.match(title)173 unit_type = m.group(1) if m else ""174175 images = []176 if img_el:177 src = img_el.get("src") or ""178 if src.startswith("//"):179 src = "https:" + src180 if src.startswith("http"):181 images.append(src)182183 listings.append(Listing(184 source=self.source_id,185 external_id=ext_id, # dérivé du titre par le builder186 url=f"{LIST_URL}#{ext_id}",187 title=title,188 address=address,189 sector="",190 # tout le parc RDR est à Trois-Rivières (incl. l'ancien191 # Cap-de-la-Madeleine, fusionné en 2002)192 city="Trois-Rivières",193 unit_type=unit_type,194 price_label=price_label,195 availability=availability,196 description="\n".join(lines)[:900],197 images=images,198 ))199 return listings200