Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/jardins_anna.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_anna.py : connecteur Les Jardins d'Anna (lesjardinsdanna.com)91# Projet domiciliaire de Nicolet (Centre-du-Québec), à 15 minutes de92# Trois-Rivières — logements 4½ et 5½ de style condo. WordPress rendu93# serveur : la page /location/ présente les typologies en sections <h3>94# (« Logements 4 ½ », « … avec verrière », « … avec verrière et garage »,95# « Logements 5 ½ ») suivies de « À partir de 1 250$ par mois, nos …96# incluent : » + liste d'inclusions. Granularité = typologie (le site ne97# publie pas d'inventaire par unité). external_id = typologie en slug.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type, strip_accents106from .base import BaseConnector107108BASE = "https://lesjardinsdanna.com"109PAGE_URL = f"{BASE}/location/"110111PRICE_RE = re.compile(r"À\s+partir\s+de\s+([\d\s ]{3,7})\$\s*par\s*mois", re.I)112UNIT_RE = re.compile(r"(\d)\s*(?:½|1/2)")113IMG_RE = re.compile(114 r"https?://lesjardinsdanna\.com/wp-content/uploads/[^\"'\s)]+"115 r"\.(?:jpg|jpeg|png|webp)", re.I)116117118def _slug(text: str) -> str:119 s = strip_accents(text.lower())120 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")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 JardinsAnnaConnector(BaseConnector):132 source_id = "jardins_anna"133 request_delay = 0.8134135 def fetch(self) -> list[Listing]:136 html = self.get(PAGE_URL).text137 soup = BeautifulSoup(html, "html.parser")138139 images = [u for u in dict.fromkeys(IMG_RE.findall(html))140 if not re.search(r"logo|icon|-\d+x\d+\.", u, re.I)][:15]141142 listings: list[Listing] = []143 for h3 in soup.find_all("h3"):144 label = re.sub(r"\s+", " ", h3.get_text(" ", strip=True))145 if not re.match(r"Logements?\s", label, re.I):146 continue147 # texte de la section : frères suivants jusqu'au prochain h3148 price = None149 price_label = ""150 amenities: list[str] = []151 node = h3152 while True:153 node = node.find_next_sibling()154 if node is None or node.name == "h3":155 break156 text = re.sub(r"\s+", " ", node.get_text(" ", strip=True))157 if not price:158 pm = PRICE_RE.search(text)159 if pm:160 price = _num(pm.group(1))161 price_label = pm.group(0)162 for li in node.find_all("li"):163 item = re.sub(r"\s+", " ", li.get_text(" ", strip=True))164 if item and item not in amenities and len(item) < 80:165 amenities.append(item)166 if price is None:167 continue168 unit_type = ""169 um = UNIT_RE.search(label)170 if um:171 unit_type = normalize_unit_type(f"{um.group(1)} ½")172 listings.append(Listing(173 source=self.source_id,174 external_id=_slug(label),175 url=PAGE_URL,176 title=f"{label} — Les Jardins d'Anna",177 address="Les Jardins d'Anna, Nicolet",178 sector="",179 city="Nicolet",180 unit_type=unit_type,181 price=price,182 price_label=price_label,183 description=f"{label} de style condo aux Jardins d'Anna, "184 "Nicolet (à 15 minutes de Trois-Rivières).",185 amenities=amenities,186 images=list(images),187 ))188 return listings189