Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/aera3r.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/aera3r.py : connecteur Aera Trois-Rivières + réseau aera.ca91# Condos locatifs neufs « tout inclus » du réseau Aera (Momentum) :92# - aera3r.com — tour du centre-ville de Trois-Rivières (875, rue de la93# Terrière), emménagement été 2026 : 1 ch. 1 600 $, 1 ch. + bureau94# 1 800 $, 2 ch. 2 300 $ tout inclus ;95# - esplanadegirouard.ca — 560, rue Girouard Ouest, Saint-Hyacinthe96# (12 unités) : 2 ch. dès 1 610 $, 3 ch. dès 1 810 $ ;97# - petitquartier.ca — maisons de ville, 603, rue Principale,98# La Présentation : dès 2 535 $/mois.99# aerasaintlambert.com ne publie AUCUN prix (formulaire seulement) et100# aerachambly.com est déjà couvert ailleurs (doc) — tous deux exclus.101# Sites Webflow statiques page unique rendus serveur : on extrait du texte102# les motifs « <typologie> à partir de (seulement) <prix>$ ». ⚠️ Les pages103# contiennent aussi des menus de budget de formulaire (« 1 100 $ par104# mois »…) — ignorés car sans « à partir de ». Granularité = typologie par105# projet. external_id = <projet>-<typologie en slug> — stable.106# -----------------------------------------------------------------------------107from __future__ import annotations108109import html as _html110import re111112from ..schema import Listing, strip_accents113from .base import BaseConnector114115# (slug projet, url, nom, adresse, ville)116SITES: tuple[tuple[str, str, str, str, str], ...] = (117 ("3r", "https://aera3r.com/", "Aera Trois-Rivières",118 "875, rue de la Terrière, Trois-Rivières", "Trois-Rivières"),119 ("girouard", "https://esplanadegirouard.ca/", "Esplanade sur Girouard",120 "560, rue Girouard Ouest, Saint-Hyacinthe", "Saint-Hyacinthe"),121 ("petitquartier", "https://petitquartier.ca/", "Le Petit Quartier",122 "603, rue Principale, La Présentation", "La Présentation"),123)124125CARD_RE = re.compile(126 r"(\d\s*chambres?(?:\s*\+\s*bureau)?|[Mm]aisons?\s+de\s+ville|[Ss]tudios?)"127 r"[^$\n]{0,80}?à\s+partir\s+de\s+(?:seulement\s+)?([\d\s ]{3,7})\$",128 re.I)129MOVE_IN_RE = re.compile(r"(?:Emménagez|Occupation|Livraison)[^<.!]{3,60}", re.I)130SCRIPT_RE = re.compile(r"<(script|style)[\s\S]*?</\1>", re.I)131TAG_RE = re.compile(r"<[^>]+>")132IMG_RE = re.compile(r'(?:src|srcset)="(images/[^"\s]+\.(?:jpg|jpeg|png|webp))')133134135def _slug(text: str) -> str:136 s = strip_accents(text.lower())137 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")138139140def _num(txt: str) -> float | None:141 n = re.sub(r"[\s ]", "", txt or "")142 try:143 return float(n)144 except ValueError:145 return None146147148class Aera3RConnector(BaseConnector):149 source_id = "aera3r"150 request_delay = 1.0151152 def fetch(self) -> list[Listing]:153 listings: list[Listing] = []154 for slug, url, name, address, city in SITES:155 try:156 resp = self.get(url)157 resp.encoding = "utf-8" # Webflow sans charset -> latin-1158 html = resp.text159 except Exception:160 continue161 listings.extend(self._parse_site(slug, url, name, address,162 city, html))163 return listings164165 def _parse_site(self, slug: str, url: str, name: str, address: str,166 city: str, html: str) -> list[Listing]:167 text = _html.unescape(SCRIPT_RE.sub(" ", html))168 flat = re.sub(r"[\s ]+", " ", TAG_RE.sub(" ", text))169170 availability = ""171 am = MOVE_IN_RE.search(flat)172 if am and re.search(r"20\d\d|immédiate|flexible", am.group(0), re.I):173 availability = re.split(r"\s+(?:Réservez|condos?)\b",174 am.group(0), flags=re.I)[0].strip()175176 images = [url + u for u in dict.fromkeys(IMG_RE.findall(html))177 if not re.search(r"logo|favicon|webclip|icon", u, re.I)][:10]178179 listings: list[Listing] = []180 seen: set[str] = set()181 for m in CARD_RE.finditer(flat):182 label = re.sub(r"\s+", " ", m.group(1)).strip()183 price = _num(m.group(2))184 if price is None or not (400 <= price <= 6000):185 continue186 label_slug = _slug(label)187 if label_slug in seen: # motifs répétés dans la page188 continue189 seen.add(label_slug)190 bedrooms = None191 bm = re.match(r"(\d)\s*chambres?", label, re.I)192 if bm:193 bedrooms = float(bm.group(1))194 unit_type = "Studio" if re.match(r"studio", label, re.I) else ""195 details = {}196 if re.search(r"maison", label, re.I):197 details["property_type"] = "Maison de ville"198 label = "Maison de ville"199 listings.append(Listing(200 source=self.source_id,201 external_id=f"{slug}-{label_slug}",202 url=url,203 title=f"{label.capitalize()} — {name}",204 address=address,205 sector="",206 city=city,207 unit_type=unit_type,208 bedrooms=bedrooms,209 price=price,210 price_label=f"à partir de {int(price)} $ par mois",211 availability=availability,212 description=f"{label.capitalize()} au {name} ({address}) — "213 "condos locatifs neufs du réseau Aera, formule "214 "tout inclus.",215 details=details,216 images=list(images),217 ))218 return listings219