Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/vestric.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/vestric.py : connecteur Vestric — Condos locatifs (vestric.ca)91# Projet unique à Candiac (Montérégie). WordPress (thème Vortex « vy_ »)92# rendu serveur : la page /les-unites liste les unités disponibles93# (li.vy_units_listing_item : no d'unité, modèle, étage, type, superficie,94# disponibilité + lien /units/unite-<no>). Granularité : unité. Prix non95# publiés (formulaire de contact avec fourchettes de budget seulement).96# -----------------------------------------------------------------------------97from __future__ import annotations9899import re100101from bs4 import BeautifulSoup102103from .base import BaseConnector104from ..schema import Listing, normalize_unit_type105106BASE = "https://vestric.ca"107LIST_URL = f"{BASE}/les-unites"108109CITY = "Candiac"110111IMG_RE = re.compile(r'https://vestric\.ca/app/uploads/'112 r'[^"\s\\)]+\.(?:jpe?g|png|webp)', re.I)113PDF_RE = re.compile(r'https://vestric\.ca/app/uploads/[^"\s\\)]+\.pdf', re.I)114SQFT_RE = re.compile(r"(\d{3,4})\s*pi", re.I)115116117class VestricConnector(BaseConnector):118 source_id = "vestric"119 request_delay = 0.6120121 def fetch(self) -> list[Listing]:122 listings: list[Listing] = []123 try:124 html = self.get(LIST_URL).text125 except Exception:126 return listings127 soup = BeautifulSoup(html, "html.parser")128129 for item in soup.select("li.vy_units_listing_item"):130 try:131 def cell(cls: str) -> str:132 el = item.select_one(f"div.vy_units_listing_{cls} span")133 return el.get_text(" ", strip=True) if el else ""134135 unit_no = cell("unit")136 if not unit_no:137 continue138 model = cell("model").replace("Modèle", "").strip()139 floor = cell("floor")140 unit_type = normalize_unit_type(cell("type"))141 sqft = None142 m = SQFT_RE.search(cell("square"))143 if m:144 sqft = float(m.group(1))145 availability = cell("availability")146147 a = item.select_one('a[href*="/units/"]')148 url = (a.get("href", "").split("#")[0] if a149 else f"{BASE}/units/unite-{unit_no}")150151 details: dict = {}152 if model:153 details["model"] = model154 if floor:155 details["floor"] = floor156157 # page détail (cache BD) : photos de l'unité158 key = f"{unit_type}|{sqft}|{availability}|{model}"159 d = self.detail(f"unite-{unit_no}", key,160 lambda url=url: self._fetch_detail(url))161162 listings.append(Listing(163 source=self.source_id,164 external_id=f"unite-{unit_no}",165 url=url,166 title=f"Unité {unit_no} ({unit_type}) — Vestric",167 address="200, avenue des Chênes, Candiac",168 city=CITY,169 unit_type=unit_type,170 availability=availability,171 area_sqft=sqft,172 details={**details, **({"plan_pdf": d["plan_pdf"]} if d.get("plan_pdf") else {})},173 images=d.get("images") or [],174 ))175 except Exception:176 continue177 return listings178179 def _fetch_detail(self, url: str) -> dict:180 out: dict = {}181 try:182 html = self.get(url).text183 except Exception:184 return out185 out["images"] = [u for u in dict.fromkeys(IMG_RE.findall(html))186 if not re.search(r"logo|icon|favicon|og-image|"187 r"decoration|bloc-vestric|"188 r"-\d{2,3}x\d{2,3}\.", u, re.I)][:15]189 pdfs = PDF_RE.findall(html)190 if pdfs:191 out["plan_pdf"] = pdfs[0]192 return out193