Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/cinquante_ans_plus.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-2513# Last Modified : 2026-09-0614#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/cinquante_ans_plus.py : connecteur Logements 50 ans et plus91# (logements50ans.ca — Gestion T. Francoeur). Trois immeubles locatifs pour92# clientèle autonome de 50 ans et plus (non RPA) : Le Chambéry et Boisé du93# Parc Équestre à Blainville, Le Bourg-Joli à Sainte-Adèle. Site vitrine94# MotoCMS rendu serveur : l'accueil publie « À PARTIR DE X$ » par immeuble,95# les pages projet donnent l'adresse, les commodités (puces « • ») et les96# photos. Granularité IMMEUBLE (aucune unité/typologie détaillée en ligne).97# -----------------------------------------------------------------------------98from __future__ import annotations99100import re101102from ..schema import Listing103from .base import BaseConnector104105BASE = "https://logements50ans.ca"106107# nom affiché sur l'accueil (repère du prix) -> (slug de page, nom, ville)108BUILDINGS = [109 ("CHAMBÉRY", "chambery", "Le Chambéry", "Blainville"),110 ("BOURG-JOLI", "bourg-joli", "Le Bourg-Joli", "Sainte-Adèle"),111 ("PARC ÉQUESTRE", "boise-du-parc-equestre",112 "Boisé du Parc Équestre", "Blainville"),113]114115PRICE_RE_TPL = r"%s.{0,600}?À PARTIR DE\s*([\d\s ,]+)\s*\$"116ADDR_RE = re.compile(117 r"(\d{1,5}[-\d]*,?\s+(?:boul\.?|rue|avenue|av\.|chemin|mont[ée]e|rang)"118 r"[^|<>]{0,60}?),\s*(?:Ville de\s*)?(Blainville|Ste-Ad[èe]le|"119 r"Sainte-Ad[èe]le)", re.I)120BULLET_RE = re.compile(r"•\s*([^|<>•]{3,60})")121IMG_RE = re.compile(122 r'(?:src|href)="(/mt-content/uploads/[^"]+\.(?:jpg|jpeg|png|webp))"', re.I)123124125def _flat(html: str) -> str:126 txt = re.sub(r"<script.*?</script>", "", html, flags=re.S)127 txt = re.sub(r"<style.*?</style>", "", txt, flags=re.S)128 txt = re.sub(r"<[^>]+>", "|", txt).replace(" ", " ")129 return re.sub(r"[ \t\n]+", " ", re.sub(r"\|+", "|", txt))130131132class CinquanteAnsPlusConnector(BaseConnector):133 source_id = "cinquante_ans_plus"134 request_delay = 0.6135136 def fetch(self) -> list[Listing]:137 # échec HONNÊTE : une erreur réseau sur l'accueil doit lever (ok=0 dans138 # sync_log) et non retourner [] — un « 0 trouvé ok » dépublie les 3139 # immeubles (missed=3, vu le 2026-09-06 16:04)140 listings: list[Listing] = []141 home = _flat(self.get(BASE + "/").text)142 if not any(marker in home for marker, *_ in BUILDINGS):143 raise RuntimeError(144 "logements50ans.ca : accueil sans aucun immeuble connu "145 "(rendu partiel ou site restructuré)")146147 for marker, slug, name, city in BUILDINGS:148 m = re.search(PRICE_RE_TPL % re.escape(marker), home, re.S)149 price_label = ""150 if m:151 price_label = ("À partir de "152 + re.sub(r"[\s ]", "", m.group(1)) + " $/mois")153154 page_url = f"{BASE}/{slug}/"155 address, amenities, images, description = "", [], [], ""156 try:157 page = self.get(page_url).text158 except Exception:159 page = ""160 if page:161 flat = _flat(page)162 am = ADDR_RE.search(flat)163 if am:164 address = am.group(1).strip(" ,")165 for b in BULLET_RE.findall(flat):166 b = b.strip(" .")167 if b and b not in amenities:168 amenities.append(b)169 images = [BASE + u for u in dict.fromkeys(IMG_RE.findall(page))170 if not re.search(r"logo|icon|-small\.", u, re.I)][:20]171 # premier paragraphe descriptif substantiel de la page projet172 for seg in flat.split("|"):173 seg = seg.strip()174 if len(seg) > 120 and "cookie" not in seg.lower():175 description = seg176 break177178 if not price_label and not address:179 continue # immeuble retiré du site180 listings.append(Listing(181 source=self.source_id,182 external_id=slug,183 url=page_url,184 title=f"{name} — logements 50 ans et plus, {city}",185 address=address,186 city=city,187 price_label=price_label,188 description=description[:1500],189 amenities=amenities[:25],190 details={"clientele": "50 ans et plus"},191 images=images,192 ))193 return listings194