Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/arpents_verts.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/arpents_verts.py : connecteur Domaine les Arpents Verts91# (domainelesarpentsverts.com — Société Immobilière GBS, ~199 portes à92# Saint-Hyacinthe). WordPress rendu serveur : une page par typologie sous93# /le-projet/ (« Logements 4 ½ », « Logements 5 ½ secteur St-Joseph »,94# « Logements 5 ½ secteur Douville »), découvertes via le menu de l'accueil.95# Granularité : une annonce par page typologie/secteur (aucun prix publié,96# superficie et commodités dans la prose).97# -----------------------------------------------------------------------------98from __future__ import annotations99100import re101102from bs4 import BeautifulSoup103104from ..schema import Listing, normalize_unit_type, parse_area_sqft105from .base import BaseConnector106107BASE = "https://domainelesarpentsverts.com"108109PAGE_LINK_RE = re.compile(110 r"https://domainelesarpentsverts\.com/le-projet/(logements-[\w\-]+)/?")111UNIT_RE = re.compile(r"(\d)\s*(?:½|1/2|-1-2)")112AREA_RE = re.compile(r"([\d\s,]{3,7})\s*(?:pieds?\s+carr[ée]s?|pi2|pi²|p\.?c\.?)", re.I)113IMG_RE = re.compile(114 r"https://domainelesarpentsverts\.com/wp-content/uploads/"115 r'[^"\s\\)]+\.(?:jpe?g|png|webp|avif)', re.I)116PHONE_RE = re.compile(r"tel:(\d{3})(\d{3})(\d{4})")117EMAIL_RE = re.compile(r"mailto:([\w.\-]+@[\w.\-]+\.\w{2,})")118119120def _sector_of(slug: str) -> str:121 if "douville" in slug:122 return "Douville"123 if "st-joseph" in slug or "saint-joseph" in slug:124 return "Saint-Joseph"125 return ""126127128class ArpentsVertsConnector(BaseConnector):129 source_id = "arpents_verts"130 request_delay = 0.8131 max_pages = 10 # garde-fou de crawl132133 def fetch(self) -> list[Listing]:134 listings: list[Listing] = []135 try:136 home = self.get(BASE + "/").text137 except Exception:138 return listings139140 slugs = list(dict.fromkeys(PAGE_LINK_RE.findall(home)))141 for slug in slugs[: self.max_pages]:142 try:143 lst = self._fetch_page(slug)144 if lst:145 listings.append(lst)146 except Exception:147 continue148 return listings149150 def _fetch_page(self, slug: str) -> Listing | None:151 url = f"{BASE}/le-projet/{slug}/"152 html = self.get(url).text153 soup = BeautifulSoup(html, "html.parser")154 for tag in soup(["script", "style", "noscript"]):155 tag.decompose()156157 h1 = soup.find("h1")158 title = h1.get_text(" ", strip=True) if h1 else \159 slug.replace("-", " ").title()160 text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))161162 m = UNIT_RE.search(f"{title} {slug}")163 unit_type = normalize_unit_type(f"{m.group(1)}½") if m else ""164 sector = _sector_of(slug)165166 # superficie dans la prose (« une superficie généreuse de 1 200167 # pieds carrés »)168 area = None169 m = AREA_RE.search(text)170 if m:171 area = parse_area_sqft(m.group(0))172173 # description : premiers paragraphes substantiels174 paras = [p.get_text(" ", strip=True) for p in soup.find_all("p")175 if len(p.get_text(strip=True)) > 80]176 description = " ".join(paras[:3])[:900]177178 # commodités : items « Les atouts de nos logements » (liste large)179 amenities = [li.get_text(" ", strip=True)180 for li in soup.select("li")181 if 8 < len(li.get_text(strip=True)) < 90182 and not li.find("a")][:18]183 # repli : les atouts sont parfois de simples div espacées184 if len(amenities) < 4:185 zone = text186 i = text.find("atouts de nos logements")187 if i > 0:188 zone = text[i:i + 1200]189 amenities = [a.strip() for a in re.findall(190 r"(?:Ascenseurs?|Air climatis[ée]|2 balcons|2 salles de bains?|"191 r"Walk-in[^,.]{0,40}|C[âa]blage[^,.]{0,30}|Espaces de rangement[^,.]{0,20}|"192 r"Syst[èe]mes? de s[ée]curit[ée]|Piscine[^,.]{0,25}|Salle Communautaire|"193 r"Gym|Biblioth[èe]que|D[ée]neigement|Stationnements?)", zone)]194195 contact: dict = {}196 m = PHONE_RE.search(html)197 if m:198 contact["phone"] = f"{m.group(1)}-{m.group(2)}-{m.group(3)}"199 m = EMAIL_RE.search(html)200 if m:201 contact["email"] = m.group(1).lower()202203 images = [u for u in dict.fromkeys(IMG_RE.findall(html))204 if not re.search(r"logo|icon|favicon|cropped-|"205 r"-\d{2,3}x\d{2,3}\.", u, re.I)][:20]206207 if not unit_type:208 return None209 return Listing(210 source=self.source_id,211 external_id=slug,212 url=url,213 title=f"Domaine les Arpents Verts — {title}",214 address="",215 sector=sector,216 city="Saint-Hyacinthe",217 unit_type=unit_type,218 area_sqft=area,219 description=description,220 amenities=list(dict.fromkeys(amenities))[:18],221 details={"contact": dict(contact)} if contact else {},222 images=images,223 )224