Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/plantation.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/plantation.py : connecteur Domaine de la Plantation91# (domainedelaplantation.ca) — Shawinigan, secteur Saint-Georges-de-Champlain92# (entre Grand-Mère et le Lac-à-la-Tortue). Nouveau quartier de 4½ neufs de93# Construction Michael Massicotte. Site vitrine Pixpa page unique rendu94# serveur : section « Prix » avec paires <h3> typologie (« Demi sous-sol95# 4 ½ » / « Étages 4 ½ ») + <h4> prix (« 1295$ par mois »), section96# « Inclusions » en items, photos Pixpa en data-src (lazy-load).97# Granularité = typologie (pas d'inventaire par unité publié).98# external_id = typologie en slug — stable.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing, normalize_unit_type, strip_accents107from .base import BaseConnector108109BASE = "https://www.domainedelaplantation.ca"110PAGE_URL = f"{BASE}/"111112ADDRESS = "Saint-Georges-de-Champlain, Shawinigan"113114PRICE_RE = re.compile(r"([\d\s ]{3,7})\$\s*par\s*mois", re.I)115UNIT_RE = re.compile(r"(\d)\s*(?:½|1/2|½)")116IMG_RE = re.compile(117 r"https://px-web-images[\w.-]*\.pixpa\.com/[^\"'\s)]+", re.I)118119120def _slug(text: str) -> str:121 s = strip_accents(text.lower())122 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")123124125def _num(txt: str) -> float | None:126 n = re.sub(r"[\s ]", "", txt or "")127 try:128 return float(n)129 except ValueError:130 return None131132133class PlantationConnector(BaseConnector):134 source_id = "plantation"135 request_delay = 0.8136137 def fetch(self) -> list[Listing]:138 html = self.get(PAGE_URL).text139 soup = BeautifulSoup(html, "html.parser")140141 # Photos (lazy-load Pixpa) — communes au projet142 images = [u for u in dict.fromkeys(143 m.group(0) for el in soup.select("[data-src]")144 for m in [IMG_RE.match(el["data-src"])] if m)][:12]145146 # Inclusions : items de la section « Inclusions »147 amenities: list[str] = []148 incl = soup.find("h2", string=re.compile(r"Inclusions", re.I))149 if incl:150 sec = incl.parent151 for _ in range(4):152 if sec is None:153 break154 txt = sec.get_text("\n", strip=True)155 if len(txt) > 60:156 break157 sec = sec.parent158 if sec is not None:159 for line in sec.get_text("\n", strip=True).split("\n"):160 line = re.sub(r"\s+", " ", line).strip()161 if line and not re.match(r"Inclusions", line, re.I) \162 and len(line) < 60 and line not in amenities:163 amenities.append(line)164165 # Accroche du projet (texte héro)166 blurb = ""167 h3 = soup.find("h3", string=re.compile(r"Grand-Mère|Lac-à-la-Tortue"))168 if h3:169 blurb = re.sub(r"\s+", " ", h3.get_text(" ", strip=True))[:600]170171 # Section « Prix » : paires h3 (typologie) + h4 (prix)172 listings: list[Listing] = []173 prix_h2 = soup.find("h2", string=re.compile(r"^\s*Prix\s*$", re.I))174 if not prix_h2:175 return listings176 sec = prix_h2177 for _ in range(4):178 sec = sec.parent179 if sec is None:180 return listings181 if sec.find("h4"):182 break183184 current_label = ""185 for el in sec.find_all(["h3", "h4"]):186 text = re.sub(r"\s+", " ", el.get_text(" ", strip=True))187 if el.name == "h3":188 current_label = text189 continue190 pm = PRICE_RE.search(text)191 if not pm or not current_label:192 continue193 unit_type = ""194 um = UNIT_RE.search(current_label)195 if um:196 unit_type = normalize_unit_type(f"{um.group(1)} ½")197 listings.append(Listing(198 source=self.source_id,199 external_id=_slug(current_label),200 url=PAGE_URL,201 title=f"{current_label} — Domaine de la Plantation",202 address=ADDRESS,203 sector="Saint-Georges-de-Champlain",204 city="Shawinigan",205 unit_type=unit_type,206 price=_num(pm.group(1)),207 price_label=text,208 description=blurb,209 amenities=list(amenities),210 images=list(images),211 ))212 current_label = ""213 return listings214