Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/le_pilier.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/le_pilier.py : connecteur Le Pilier (lepilierlevis.com) — condos91# locatifs neufs au 1275, rue J.-B.-Demers à Lévis (sections 3 et 6 étages).92# WordPress + plugin maison « themelio-real-estate » : la page /projet/93# rend côté serveur un <table class="units-table"> (Unité, Étage,94# Superficie, Pièces, Prix, Disponibilité, lien /units/unite-NNN/), filtré95# par défaut sur les unités disponibles ; la page unité fournit le plan.96# Granularité : unité, avec prix.97# -----------------------------------------------------------------------------98from __future__ import annotations99100import hashlib101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type, parse_price106from .base import BaseConnector107108BASE = "https://lepilierlevis.com"109LIST_URL = f"{BASE}/projet/"110111SQFT_RE = re.compile(r"([\d\s]+)\s*pi²", re.I)112FLOOR_RE = re.compile(r"(\d+)")113PLAN_RE = re.compile(r'src="(https://lepilierlevis\.com/wp-content/uploads/'114 r'[^"]+\.(?:avif|png|jpe?g|webp))"', re.I)115116ADDRESS = "1275, rue J.-B.-Demers, Lévis"117CONTACT = {"phone": "418-836-7666"}118119120class LePilierConnector(BaseConnector):121 source_id = "le_pilier"122 request_delay = 0.6123124 def fetch(self) -> list[Listing]:125 listings: list[Listing] = []126 try:127 html = self.get(LIST_URL).text128 except Exception:129 return listings130 soup = BeautifulSoup(html, "html.parser")131 table = soup.select_one("table.units-table")132 if table is None:133 return listings134135 seen: set[str] = set()136 for row in table.select("tbody tr"):137 try:138 cells = row.find_all("td")139 if len(cells) < 7:140 continue141 unit_no, floor, area_txt, rooms, price_txt, avail = \142 [c.get_text(" ", strip=True) for c in cells[:6]]143 if not unit_no or not re.match(r"^disponible", avail, re.I):144 continue # réservé / loué145 ext_id = f"unite-{unit_no}"146 if ext_id in seen:147 continue148 seen.add(ext_id)149150 link = cells[6].find("a")151 url = link["href"] if link and link.get("href") else LIST_URL152153 area = None154 m = SQFT_RE.search(area_txt)155 if m:156 area = float(m.group(1).replace(" ", "")157 .replace(" ", "").replace(" ", ""))158 unit_type = normalize_unit_type(rooms)159160 # plan de l'unité sur sa page /units/unite-NNN/ (cache détail161 # invalidé quand la ligne du tableau change)162 key = hashlib.sha1(163 "|".join([unit_no, floor, area_txt, rooms, price_txt,164 avail]).encode()).hexdigest()165 d = self.detail(ext_id, key,166 lambda u=url: self._fetch_unit(u))167168 listings.append(Listing(169 source=self.source_id,170 external_id=ext_id,171 url=url,172 title=f"Unité {unit_no} — Le Pilier Lévis",173 address=ADDRESS,174 city="Lévis",175 unit_type=unit_type,176 price=parse_price(price_txt),177 price_label=price_txt,178 availability=avail,179 area_sqft=area,180 description=f"Unité {unit_no} ({unit_type}), {floor} — "181 "Le Pilier, condos locatifs neufs au cœur "182 "de Lévis.",183 details={"floor": floor, "contact": dict(CONTACT)},184 images=d.get("images") or [],185 ))186 except Exception:187 continue188 return listings189190 def _fetch_unit(self, url: str) -> dict:191 """Plan/photos de la page unité (/units/unite-NNN/)."""192 out: dict = {}193 try:194 html = self.get(url).text195 except Exception:196 return out197 imgs = [u for u in PLAN_RE.findall(html)198 if "logo" not in u.lower()]199 if imgs:200 out["images"] = list(dict.fromkeys(imgs))[:5]201 return out202