Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/treana.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/treana.py : connecteur TREANA (treana.ca) — condos locatifs en91# Montérégie : Saint-Jean-sur-Richelieu (374-378, rue Jacques-Cartier Sud),92# Sainte-Catherine phases I et II (1155, rue Centrale) et Venise-en-Québec93# (4 immeubles TREANA III à VI). WordPress + Elementor rendu serveur :94# chaque page projet porte une ou plusieurs tables d'unités (colonnes95# « Unité | Type | Étage | Grandeur | Superficie | Prix/mois »). Seules les96# tables avec la colonne « Type » sont lues (les tables 5 colonnes en aval97# sont des fiches par typologie qui répètent les mêmes unités). Le site98# n'affiche pas de prix : « - » = sur demande (ingéré sans prix), « LOUÉ »99# = exclu — la page Sainte-Catherine II peut donc donner 0 annonce.100# À Venise, l'immeuble (TREANA III…VI) vient du titre précédant la table.101# -----------------------------------------------------------------------------102from __future__ import annotations103104import re105106from bs4 import BeautifulSoup107108from ..schema import Listing, normalize_unit_type, parse_price109from .base import BaseConnector110111BASE = "https://treana.ca"112113# clé de page -> (chemin, ville, adresse civique)114PAGES = {115 "saint-jean": ("/saint-jean-sur-richelieu/", "Saint-Jean-sur-Richelieu",116 "374-378, rue Jacques-Cartier Sud, Saint-Jean-sur-Richelieu"),117 "venise": ("/venise-en-quebec/", "Venise-en-Québec", ""),118 "ste-catherine-1": ("/sainte-catherine_phase_i/", "Sainte-Catherine",119 "1155, rue Centrale, Sainte-Catherine"),120 "ste-catherine-2": ("/sainte-catherine-phase-ii/", "Sainte-Catherine",121 "1155, rue Centrale, Sainte-Catherine"),122}123124LOUE_RE = re.compile(r"lou[ée]", re.I)125GRANDEUR_RE = re.compile(r"^\d\s*1/2$")126SQFT_RE = re.compile(r"([\d\s ]{3,7})\s*pi\.?\s*ca", re.I)127BLDG_RE = re.compile(r"^TREANA\s+([IVX]+)\b", re.I)128IMG_RE = re.compile(129 r"https://(?:www\.)?treana\.ca/wp-content/uploads/[^\"\s\\']+"130 r"\.(?:jpe?g|png|webp)", re.I)131SKIP_IMG_RE = re.compile(132 r"logo|icon|favicon|cropped-|plan|-\d{2,4}x\d{2,4}\.", re.I)133134135class TreanaConnector(BaseConnector):136 source_id = "treana"137 request_delay = 0.6138139 def fetch(self) -> list[Listing]:140 listings: list[Listing] = []141 for page_key, (path, city, address) in PAGES.items():142 try:143 html = self.get(f"{BASE}{path}").text144 except Exception:145 continue146 self._parse_page(html, page_key, f"{BASE}{path}",147 city, address, listings)148 return listings149150 def _parse_page(self, html: str, page_key: str, url: str, city: str,151 address: str, listings: list[Listing]) -> None:152 soup = BeautifulSoup(html, "html.parser")153154 images = [u for u in dict.fromkeys(IMG_RE.findall(html))155 if not SKIP_IMG_RE.search(u)][:8]156 pdf_el = soup.find("a", href=re.compile(r"\.pdf$", re.I))157 fiche_pdf = pdf_el["href"] if pdf_el else ""158159 seen: set[str] = set()160 for table in soup.find_all("table"):161 head = table.find("tr")162 if head is None:163 continue164 cols = [c.get_text(" ", strip=True)165 for c in head.find_all(["td", "th"])]166 if "Type" not in cols or "Unité" not in cols:167 continue # fiche par typologie : ignorée168169 # immeuble : titre « TREANA III » précédant la table (Venise)170 building = ""171 h = table.find_previous(["h1", "h2", "h3", "h4"])172 for _ in range(4):173 if h is None:174 break175 m = BLDG_RE.match(h.get_text(" ", strip=True))176 if m:177 building = f"TREANA {m.group(1).upper()}"178 break179 h = h.find_previous(["h1", "h2", "h3", "h4"])180181 idx = {name: i for i, name in enumerate(cols)}182 for tr in table.find_all("tr")[1:]:183 try:184 tds = [td.get_text(" ", strip=True)185 for td in tr.find_all("td")]186 if len(tds) < len(cols):187 continue188 unit_no = tds[idx["Unité"]]189 if not re.fullmatch(r"\d{2,4}", unit_no):190 continue191 price_txt = tds[idx["Prix/mois"]]192 if LOUE_RE.search(price_txt):193 continue # unité louée : exclue194 grandeur = tds[idx["Grandeur"]]195 if not GRANDEUR_RE.match(grandeur):196 continue197 unit_type = normalize_unit_type(grandeur)198199 bslug = re.sub(r"[^a-z0-9]+", "-", building.lower())\200 .strip("-")201 ext_id = "-".join(x for x in (page_key, bslug, unit_no)202 if x)203 if ext_id in seen:204 continue205 seen.add(ext_id)206207 area = None208 m = SQFT_RE.search(tds[idx["Superficie"]])209 if m:210 try:211 area = float(re.sub(r"[^\d]", "", m.group(1)))212 except ValueError:213 area = None214215 details: dict = {}216 floor = tds[idx["Étage"]] if "Étage" in idx else ""217 if floor:218 details["floor_label"] = floor219 type_label = tds[idx["Type"]]220 if type_label and type_label not in {"-", "–"}:221 details["type_plan"] = type_label222 if fiche_pdf:223 details["fiche_pdf"] = fiche_pdf224225 title = f"{unit_type} — Unité {unit_no}, " + \226 (building or "TREANA") + f" ({city})"227 listings.append(Listing(228 source=self.source_id,229 external_id=ext_id,230 url=url,231 title=title,232 address=address,233 city=city,234 unit_type=unit_type,235 price=parse_price(price_txt),236 price_label="" if price_txt in {"-", "–"}237 else price_txt,238 area_sqft=area,239 amenities=["Tout inclus"]240 if "TOUS INCLUS" in html else [],241 details=details,242 images=images,243 ))244 except Exception:245 continue246