Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/roussin.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0613# Last Modified : 2026-08-0814#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/roussin.py : connecteur Immeubles Roussin (immeublesroussin.com)91# Immeubles/projets résidentiels (L'Aromate, L'Allié, La Vigie, etc.) —92# une annonce par type d'unité et par immeuble, prix « à partir de ».93# Les pages commerciales (locaux, bureaux, entrepôts) sont exclues.94# Commodités : paires icône+texte Elementor (Gym, Eau chaude, Animaux95# acceptés (20lb et moins)…) ; contact : liens tel:/mailto: structurés.96# -----------------------------------------------------------------------------97from __future__ import annotations9899import re100101from bs4 import BeautifulSoup102103from ..schema import Listing, infer_city, normalize_unit_type, parse_price104from .base import BaseConnector105106BASE = "https://immeublesroussin.com"107INDEX = f"{BASE}/location-condo-appartement-quebec/"108109# Lignes de prix : « Loft à partir de 1200$ », « 3 ½ à partir de 1595$ »...110PRICE_LINE_RE = re.compile(111 r"((?:\d\s*(?:½|1/2))|Loft|Studio|Maison)[^<>$]{0,30}?"112 r"à\s+partir\s+de\s*([\d][\d\s ,]*)\s*\$",113 re.I,114)115IMG_RE = re.compile(116 r"https://immeublesroussin\.com/wp-content/uploads/[^\"'\\\s\)]+"117 r"\.(?:jpg|jpeg|png|webp)", re.I)118IMG_NOISE_RE = re.compile(r"favicon|logo|icon|cropped|header", re.I)119ADDR_RE = re.compile(120 r"\d{2,5}[,]?\s+(?:rue|avenue|av\.|boulevard|boul\.|chemin|ch\.|place)"121 r"\s[^<>{}\"]{3,60}", re.I)122BUILDING_RE = re.compile(r"/location-condo-appartement-quebec/([a-z0-9\-]+)/?$")123124125class RoussinConnector(BaseConnector):126 source_id = "roussin"127 request_delay = 0.6128 max_buildings = 30 # garde-fou129130 def fetch(self) -> list[Listing]:131 # 1) Découvrir les pages d'immeubles résidentiels132 html = self.get(INDEX).text133 slugs: list[str] = []134 for href in re.findall(r'href="([^"]+)"', html):135 m = BUILDING_RE.search(href.split("#")[0].split("?")[0])136 if m and m.group(1) not in slugs:137 slugs.append(m.group(1))138139 listings: list[Listing] = []140 for slug in slugs[: self.max_buildings]:141 url = f"{INDEX}{slug}/"142 try:143 page = self.get(url).text144 except Exception:145 continue146 try:147 listings.extend(self._parse_building(slug, url, page))148 except Exception:149 continue150 return listings151152 def _parse_building(self, slug: str, url: str, page: str) -> list[Listing]:153 soup = BeautifulSoup(page, "html.parser")154155 # Nom + secteur depuis le <title> :156 # « L'Aromate - Location de condos à Ste-Foy | Immeubles Roussin »157 title_tag = soup.find("title")158 raw_title = title_tag.get_text(strip=True) if title_tag else slug159 name = re.split(r"\s+[-–|]\s+", raw_title)[0].strip() or slug160 if re.search(r"louer|condos? neufs?", name, re.I):161 # Titre générique (« Condos à louer à Lévis ») : essayer la partie162 # après « : », sinon un nom dérivé du slug.163 m = re.search(r":\s*([^|]+)", raw_title)164 name = (m.group(1).strip() if m165 else slug.replace("-", " ").strip().title())166167 # Description (og:description)168 desc = ""169 og = soup.find("meta", attrs={"property": "og:description"})170 if og and og.get("content"):171 desc = og["content"].strip()[:600]172173 # Adresse civique (en excluant le bureau administratif de Roussin)174 address = ""175 for cand in ADDR_RE.findall(page):176 if re.search(r"bureau", cand, re.I):177 continue178 address = re.sub(r"\s+", " ", cand).strip().rstrip(",")179 break180181 # Secteur : mots-clés dans le titre puis dans l'adresse182 sector = ""183 m = re.search(r"(Sainte-Foy|Ste-Foy|L[ée]vis|Beauport|Sillery|"184 r"Cap-Rouge|St-Augustin)", f"{raw_title} {address}", re.I)185 if m:186 sector = m.group(1)187188 # Images (galerie de l'immeuble)189 images = [u for u in dict.fromkeys(IMG_RE.findall(page))190 if not IMG_NOISE_RE.search(u)][:25]191192 # Commodités : paires icône (« iconeGym.jpg ») + widget texte Elementor193 amenities: list[str] = []194 for img in soup.select('img[src*="icone"]'):195 cont = img.find_parent(class_="elementor-container")196 if not cont:197 continue198 for te in cont.select(".elementor-widget-text-editor "199 ".elementor-widget-container"):200 t = te.get_text(" ", strip=True)201 if 2 < len(t) < 45 and t not in amenities:202 amenities.append(t)203 amenities = amenities[:20]204205 # Contact du gestionnaire (liens tel:/mailto: structurés)206 details: dict = {}207 contact: dict = {}208 tel = soup.select_one('a[href^="tel:"]')209 if tel:210 tm = re.search(r"\(?([2-9]\d{2})\)?[\s.%20\-]*(\d{3})[\s.\-]?(\d{4})",211 (tel.get("href") or "").replace("%20", ""))212 if tm:213 contact["phone"] = f"{tm.group(1)}-{tm.group(2)}-{tm.group(3)}"214 mail = soup.select_one('a[href^="mailto:"]')215 if mail:216 contact["email"] = (mail.get("href") or "")[7:].split("?")[0]217 if contact:218 details["contact"] = contact219220 # Types d'unités avec prix « à partir de »221 text = soup.get_text(" ", strip=True)222 seen: set[str] = set()223 out: list[Listing] = []224 for type_raw, amount in PRICE_LINE_RE.findall(text):225 unit_type = normalize_unit_type(type_raw)226 if not unit_type or unit_type in seen:227 continue228 seen.add(unit_type)229 price_label = f"{type_raw.strip()} à partir de {amount.strip()}$"230 key = re.sub(r"[^a-z0-9]+", "-", unit_type.lower().replace("½", "5"))231 out.append(Listing(232 source=self.source_id,233 external_id=f"{slug}--{key}",234 url=url,235 title=f"{name} — {unit_type}",236 address=address,237 sector=sector,238 city=infer_city(sector),239 unit_type=unit_type,240 price=parse_price(f"{amount}$"),241 price_label=price_label,242 description=desc,243 amenities=list(amenities),244 details=dict(details),245 images=images,246 ))247248 # Aucun prix affiché : une annonce par immeuble quand même249 if not out:250 out.append(Listing(251 source=self.source_id,252 external_id=slug,253 url=url,254 title=name,255 address=address,256 sector=sector,257 city=infer_city(sector),258 description=desc,259 amenities=list(amenities),260 details=dict(details),261 images=images,262 ))263 return out264