Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/terrasse_pionniers.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/terrasse_pionniers.py : connecteur Terrasse des Pionniers91# (terrassedespionniers.ca — appartements locatifs neufs long terme au92# 973, rue Saint-Faustin à Mont-Blanc (Laurentides), près de la station93# de ski ; 16 unités 4½ + 4 unités 5½). WordPress/Elementor + JetEngine94# rendu SERVEUR : l'accueil expose une carte par TYPOLOGIE (badge de95# disponibilité dynamique « Disponible »/« Non-Disponible », nb d'unités,96# prix « à partir de », superficie) ; la fiche liste les inclusions97# (« Le loyer comprend : ») et la galerie. Granularité TYPOLOGIE98# (external_id = slug WordPress de la fiche, stable). Le badge de99# disponibilité est repris tel quel dans `availability` (peut être100# « Non-Disponible » quand tout est loué — bail au 1er juillet).101# -----------------------------------------------------------------------------102from __future__ import annotations103104import re105106from bs4 import BeautifulSoup107108from ..schema import Listing, normalize_unit_type109from .base import BaseConnector110111BASE = "https://terrassedespionniers.ca"112HOME_URL = f"{BASE}/"113ADDRESS = "973, rue Saint-Faustin"114CITY = "Mont-Blanc"115116TYPE_RE = re.compile(r"^\s*(\d)\s*½\s*$")117COUNT_RE = re.compile(r"(\d+)\s*Unités", re.I)118PRICE_RE = re.compile(r"à partir de\s*([\d\s ,]+)\s*\$", re.I)119AREA_RE = re.compile(r"([\d\s ]+)\s*pi²")120BADGE_RE = re.compile(r"^(Non-)?Disponible", re.I)121IMG_RE = re.compile(122 r"https://terrassedespionniers\.ca/wp-content/uploads/"123 r"[^\"\s\\]+?\.(?:jpe?g|png|webp)", re.I)124IMG_SIZE_RE = re.compile(r"-\d+x\d+(?=\.(?:jpe?g|png|webp))", re.I)125126127class TerrassePionniersConnector(BaseConnector):128 source_id = "terrasse_pionniers"129 request_delay = 0.8130131 def fetch(self) -> list[Listing]:132 try:133 soup = BeautifulSoup(self.get(HOME_URL).text, "html.parser")134 except Exception:135 return []136 listings: list[Listing] = []137 for card in soup.select(".jet-listing-grid__item"):138 wrap = card.select_one("[data-url]")139 url = wrap["data-url"] if wrap else ""140 if not url or "/appartements/" not in url:141 continue142 ext_id = url.rstrip("/").rsplit("/", 1)[-1]143 text = re.sub(r"\s+", " ", card.get_text(" ", strip=True))144145 unit_type = ""146 for h in card.select("h1, h2, h3, h4, h5, h6"):147 m = TYPE_RE.match(h.get_text(" ", strip=True))148 if m:149 unit_type = normalize_unit_type(f"{m.group(1)} 1/2")150 break151 if not unit_type:152 continue153154 badge = ""155 for h in card.select("h6"):156 m = BADGE_RE.match(h.get_text(" ", strip=True))157 if m:158 badge = h.get_text(" ", strip=True)159 break160 price = None161 m = PRICE_RE.search(text)162 if m:163 try:164 price = float(re.sub(r"[\s ,]", "", m.group(1)))165 except ValueError:166 pass167 area = None168 m = AREA_RE.search(text)169 if m:170 try:171 area = float(re.sub(r"[\s ]", "", m.group(1)))172 except ValueError:173 pass174 m = COUNT_RE.search(text)175 nb_units = m.group(1) if m else ""176177 # fiche typologie (cache BD) : description, inclusions, galerie178 detail = self.detail(ext_id, f"{badge}|{price}|{area}",179 lambda u=url: self._detail(u))180 details: dict = {}181 if nb_units:182 details["nb_unites"] = nb_units183 listings.append(Listing(184 source=self.source_id,185 external_id=ext_id, # slug WP de la fiche typologie186 url=url,187 title=f"Appartement {unit_type} — Terrasse des Pionniers",188 address=ADDRESS,189 city=CITY,190 unit_type=unit_type,191 price=price,192 price_label=f"à partir de {price:.0f} $ /mois" if price else "",193 availability=badge,194 area_sqft=area,195 furnished=False, # « Non meublés » sur la fiche196 description=detail.get("description", "")[:1500],197 amenities=detail.get("amenities") or [],198 details=details,199 images=detail.get("images") or [],200 ))201 return listings202203 # -- fiche typologie (4½ / 5½) ------------------------------------------------204 def _detail(self, url: str) -> dict:205 try:206 html = self.get(url).text207 except Exception:208 return {}209 soup = BeautifulSoup(html, "html.parser")210 out: dict = {}211 text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))212 # description : phrase de présentation + emplacement213 parts: list[str] = []214 m = re.search(r"(Chaque \d ½ offre[^|]+?\.)\s", text)215 if m:216 parts.append(m.group(1).strip())217 m = re.search(r"Emplacement idéal\s*:\s*([^.]+\.)", text)218 if m:219 parts.append("Emplacement : " + m.group(1).strip())220 out["description"] = " ".join(parts)221 # inclusions : « Le loyer comprend : » + description des unités222 amen: list[str] = []223 m = re.search(r"Le loyer comprend\s*:\s*(.+?)Exclus de la location",224 text)225 if m:226 for item in re.split(r"(?<=[a-zà-ü)\.])\s+(?=[A-ZÉÈÀ])",227 m.group(1).strip()):228 item = item.strip(" .")229 if 3 < len(item) < 90 and item not in amen:230 amen.append(item)231 out["amenities"] = amen[:15]232 imgs = []233 for u in dict.fromkeys(IMG_RE.findall(html)):234 u = IMG_SIZE_RE.sub("", u)235 if not re.search(r"logo|icon|favicon|ImageWithFallback", u, re.I) \236 and u not in imgs:237 imgs.append(u)238 out["images"] = imgs[:20]239 return out240