Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/double_v.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/double_v.py : connecteur Le Double V (ledoublev.ca)91# Collection de projets locatifs en Montérégie : Sainte-Julie (500, boul.92# Saint-Joseph), McMasterville (235, chemin du Richelieu — livraison Hiver93# 2026-2027) et Saint-Hyacinthe (845, avenue Crémazie, secteur Douville).94# WordPress + Bricks rendu serveur : chaque page projet expose la grille95# des unités en div[data-unit-post-title] avec data-unit-rooms (« 3 ½ »),96# data-unit-surface, data-unit-floor et plans (data-unit-plan-image/floor).97# Le statut (« Disponible »/« Loué ») est dans le texte de la ligne — seules98# les unités « Disponible » sont ingérées. Les prix sont par typologie99# (« 3 ½ À partir de 1900$ par mois » dans le texte de la page) ; une100# mention de saison en tête de page (« Hiver 2026-2027 ») sert de101# disponibilité (projet en prélocation).102# -----------------------------------------------------------------------------103from __future__ import annotations104105import re106107from bs4 import BeautifulSoup108109from ..schema import Listing, normalize_unit_type110from .base import BaseConnector111112BASE = "https://www.ledoublev.ca"113114# clé de page -> (chemin, ville, adresse civique)115PAGES = {116 "sainte-julie": ("/sainte-julie/", "Sainte-Julie",117 "500, boulevard Saint-Joseph, Sainte-Julie"),118 "mcmasterville": ("/mcmasterville/", "McMasterville",119 "235, chemin du Richelieu, McMasterville"),120 "saint-hyacinthe": ("/saint-hyacinthe/", "Saint-Hyacinthe",121 "845, avenue Crémazie, Saint-Hyacinthe"),122}123124PRICE_TYPE_RE = re.compile(125 r"(\d)\s*½\s*À partir de\s*(\d[\d\s ]{2,6})\s*\$\s*par mois", re.I)126DELIVERY_RE = re.compile(127 r"\b((?:Hiver|Printemps|Été|Automne)\s+\d{4}(?:-\d{4})?)")128BEDS_RE = re.compile(r"(\d)\s*chambres?", re.I)129IMG_RE = re.compile(130 r"https://www\.ledoublev\.ca/wp-content/uploads/[^\"\s\\']+"131 r"\.(?:jpe?g|png|webp)", re.I)132SKIP_IMG_RE = re.compile(133 r"logo|icon|favicon|cropped|plan|-\d{2,4}x\d{2,4}\.", re.I)134135136class DoubleVConnector(BaseConnector):137 source_id = "double_v"138 request_delay = 0.6139140 def fetch(self) -> list[Listing]:141 listings: list[Listing] = []142 for page_key, (path, city, address) in PAGES.items():143 try:144 html = self.get(f"{BASE}{path}").text145 except Exception:146 continue147 self._parse_page(html, page_key, f"{BASE}{path}",148 city, address, listings)149 return listings150151 def _parse_page(self, html: str, page_key: str, url: str, city: str,152 address: str, listings: list[Listing]) -> None:153 soup = BeautifulSoup(html, "html.parser")154 text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))155156 # prix plancher par typologie : « 3 ½ À partir de 1900$ par mois »157 prices: dict[str, tuple[float, str]] = {}158 for m in PRICE_TYPE_RE.finditer(text):159 t = f"{m.group(1)}½"160 try:161 prices[t] = (float(re.sub(r"[^\d]", "", m.group(2))),162 f"À partir de {re.sub(r'[ ]', ' ', m.group(2)).strip()}$ par mois")163 except ValueError:164 continue165166 # projet en prélocation : saison de livraison en tête de page167 m = DELIVERY_RE.search(text[:2000])168 delivery = m.group(1) if m else ""169170 images = [u for u in dict.fromkeys(IMG_RE.findall(html))171 if not SKIP_IMG_RE.search(u)][:8]172173 seen: set[str] = set()174 for row in soup.select("div[data-unit-post-title]"):175 try:176 unit_no = row.get("data-unit-post-title", "").strip()177 if not re.fullmatch(r"[\w-]{1,10}", unit_no):178 continue179 ext_id = f"{page_key}-{unit_no}"180 if ext_id in seen:181 continue182183 rtext = row.get_text(" ", strip=True)184 if not re.search(r"\bDisponible\b", rtext, re.I):185 continue # Loué / Réservé : exclu186 seen.add(ext_id)187188 rooms = row.get("data-unit-rooms", "")189 unit_type = normalize_unit_type(re.sub(r"\s+", "", rooms))190 if not re.match(r"^\d½$", unit_type):191 continue192193 area = None194 surf = row.get("data-unit-surface", "")195 digits = re.sub(r"[^\d]", "", surf)196 if digits:197 area = float(digits)198199 bedrooms = None200 m = BEDS_RE.search(rtext)201 if m:202 bedrooms = float(m.group(1))203204 price, price_label = prices.get(unit_type, (None, ""))205206 details: dict = {}207 floor = row.get("data-unit-floor", "")208 if floor:209 details["floor_label"] = floor210 if row.get("data-unit-plan-image"):211 details["plan_image"] = row["data-unit-plan-image"]212213 listings.append(Listing(214 source=self.source_id,215 external_id=ext_id,216 url=url,217 title=f"{unit_type} — Unité {unit_no}, "218 f"Le Double V {city}",219 address=address,220 city=city,221 unit_type=unit_type,222 bedrooms=bedrooms,223 price=price,224 price_label=price_label,225 availability=delivery or "Disponible",226 area_sqft=area,227 details=details,228 images=images,229 ))230 except Exception:231 continue232