Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/jardins_nd.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/jardins_nd.py : connecteur Les Jardins Notre Dame91# (logement-victoriaville.jardinsnotredame.com) — Victoriaville,92# 465, rue Notre-Dame Ouest. Complexe locatif neuf tout inclus (studios93# meublés à 5½). Landing Unbounce page unique (~580 Ko) rendue serveur :94# pas de sélecteurs sémantiques (divs lp-pom-*) — on parse le TEXTE en ordre95# du document : une ligne typologie (« Studios », « 3 1/2 », « 4 1/2 »,96# « 5 1/2 ») suivie de lignes d'inclusions puis d'une fourchette de prix97# (« De 1 550 $ à 1 625 $ /mois »). Granularité = typologie (pas98# d'inventaire par unité publié). external_id = typologie en slug.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import html as _html103import re104105from ..schema import Listing, normalize_unit_type106from .base import BaseConnector107108PAGE_URL = "https://logement-victoriaville.jardinsnotredame.com/"109110ADDRESS = "465, rue Notre-Dame Ouest, Victoriaville"111112TYPE_RE = re.compile(r"^(Studios?|\d\s*(?:1/2|½))$", re.I)113PRICE_RANGE_RE = re.compile(114 r"^(?:De\s+)?([\d\s ]{3,7})\$\s*(?:à\s*([\d\s ]{3,7})\$)?\s*/\s*mois",115 re.I)116IMG_RE = re.compile(117 r"//d9hhrg4mnvzow\.cloudfront\.net/[^\"'\s),]+\.(?:jpg|jpeg|png|webp)",118 re.I)119SCRIPT_RE = re.compile(r"<(script|style)[\s\S]*?</\1>", re.I)120TAG_RE = re.compile(r"<[^>]+>")121122123def _num(txt: str) -> float | None:124 n = re.sub(r"[\s ]", "", txt or "")125 try:126 return float(n)127 except ValueError:128 return None129130131class JardinsNotreDameConnector(BaseConnector):132 source_id = "jardins_nd"133 request_delay = 0.8134135 def fetch(self) -> list[Listing]:136 html = self.get(PAGE_URL).text137138 # Photos (CDN Unbounce) : garder la variante la plus large par visuel139 images: list[str] = []140 for u in dict.fromkeys(IMG_RE.findall(html)):141 u = "https:" + u142 base = re.sub(r"_[\w]+o\.(jpg|jpeg|png|webp)$", "", u)143 if not any(im.startswith(base) for im in images):144 images.append(u)145 images = images[:12]146147 # HTML -> lignes de texte en ordre du document148 txt = SCRIPT_RE.sub(" ", html)149 txt = _html.unescape(TAG_RE.sub("\n", txt))150 lines = [re.sub(r"[\s ]+", " ", l).strip() for l in txt.split("\n")]151 lines = [l for l in lines if l]152153 listings: list[Listing] = []154 seen: set[str] = set()155 current: str = ""156 amenities: list[str] = []157 for line in lines:158 if TYPE_RE.match(line):159 current = line160 amenities = []161 continue162 if not current:163 continue164 pm = PRICE_RANGE_RE.match(line)165 if not pm:166 # inclusions courtes entre la typologie et le prix167 if len(line) < 60 and not re.search(r"Voir|plan", line, re.I):168 amenities.append(line)169 elif len(amenities) > 4: # trop loin : carte abandonnée170 current = ""171 continue172 unit_type = "Studio" if re.match(r"studio", current, re.I) \173 else normalize_unit_type(current)174 ext_id = "studio" if unit_type == "Studio" \175 else unit_type.replace("½", ".5")176 if ext_id in seen: # la page répète les cartes177 current = ""178 continue179 seen.add(ext_id)180 price = _num(pm.group(1))181 price_max = _num(pm.group(2)) if pm.group(2) else None182 details: dict = {}183 if price_max:184 details["price_max"] = price_max185 listings.append(Listing(186 source=self.source_id,187 external_id=ext_id,188 url=PAGE_URL,189 title=f"{unit_type} — Les Jardins Notre Dame",190 address=ADDRESS,191 sector="",192 city="Victoriaville",193 unit_type=unit_type,194 price=price,195 price_label=pm.group(0).strip(),196 description=f"{unit_type} tout inclus aux Jardins Notre Dame, "197 "complexe locatif neuf de Victoriaville "198 "(piscine, tennis, espaces communs).",199 amenities=list(dict.fromkeys(amenities)),200 details=details,201 images=list(images),202 ))203 current = ""204 return listings205