Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/lienard.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-2513# Last Modified : 2026-09-0414#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/lienard.py : connecteur Liénard (lienard.ca) — condos locatifs91# à Sainte-Foy (Québec), 2 phases : 950, rue Liénard (unités 1xx-6xx) et92# 1000, avenue Myrand (unités 1001-6006). WordPress rendu serveur ; les93# disponibilités vivent dans des plans d'étage interactifs Image Map Pro :94# chaque <script> embarque `var settings = {...}` (JSON) avec un spot par95# unité et un tooltip « Unité NNN » + statut (Disponible / Loué / Non96# disponible). Granularité : unité. Ni prix ni typologie publiés.97# -----------------------------------------------------------------------------98from __future__ import annotations99100import json101import re102103from ..schema import Listing104from .base import BaseConnector105106BASE = "https://lienard.ca"107# Les deux pages embarquent les 14 cartes (toutes phases) ; une seule suffit,108# la seconde sert de repli si la première change.109PAGES = [f"{BASE}/plans-et-disponibilites/",110 f"{BASE}/plans-et-disponibilites-phase-2/"]111PAGE_PHASE2 = f"{BASE}/plans-et-disponibilites-phase-2/"112113SETTINGS_RE = re.compile(r"var settings = (\{\"id\":\d+.*?\});", re.S)114UNIT_RE = re.compile(r"Unité\s+(\d+)", re.I)115116ADDR_PHASE1 = "950, rue Liénard, Québec"117ADDR_PHASE2 = "1000, avenue Myrand, Québec"118AMENITIES = ["Chauffé", "Éclairé", "Climatisé", "Wi-Fi illimité",119 "Électroménagers inclus"]120121122def _tooltip_texts(node, acc: list[str]) -> list[str]:123 """Aplati récursivement les champs `text` d'un tooltip Image Map Pro."""124 if isinstance(node, dict):125 for k, v in node.items():126 if k == "text" and isinstance(v, str):127 acc.append(v.strip())128 else:129 _tooltip_texts(v, acc)130 elif isinstance(node, list):131 for x in node:132 _tooltip_texts(x, acc)133 return acc134135136class LienardConnector(BaseConnector):137 source_id = "lienard"138 request_delay = 0.6139140 def fetch(self) -> list[Listing]:141 listings: list[Listing] = []142 html = ""143 for page in PAGES:144 try:145 html = self.get(page).text146 except Exception:147 continue148 if SETTINGS_RE.search(html):149 break150 if not html:151 return listings152153 seen: set[str] = set()154 for m in SETTINGS_RE.finditer(html):155 try:156 settings = json.loads(m.group(1))157 except ValueError:158 continue159 map_name = (settings.get("general") or {}).get("name", "")160 plan_img = ((settings.get("image") or {}).get("url") or "")161 for spot in settings.get("spots") or []:162 texts = _tooltip_texts(spot.get("tooltip_content") or {}, [])163 joined = " | ".join(texts)164 um = UNIT_RE.search(joined)165 if not um:166 continue167 unit_no = um.group(1)168 status = next((t for t in texts if t and not UNIT_RE.match(t)),169 "")170 # ne garder que les unités réellement offertes en location171 if not re.match(r"^disponible", status, re.I):172 continue173 ext_id = f"unite-{unit_no}"174 if ext_id in seen:175 continue176 seen.add(ext_id)177 phase2 = len(unit_no) == 4 or "phase2" in map_name.lower()178 address = ADDR_PHASE2 if phase2 else ADDR_PHASE1179 floor = unit_no[0]180 listings.append(Listing(181 source=self.source_id,182 external_id=ext_id,183 url=PAGE_PHASE2 if phase2 else PAGES[0],184 title=f"Unité {unit_no} — Liénard"185 f"{' phase 2' if phase2 else ''}",186 address=address,187 sector="Sainte-Foy",188 city="Québec",189 price_label="Prix sur demande",190 availability=status,191 description=f"Unité {unit_no}, {floor}e étage — condo "192 "locatif du projet Liénard à Sainte-Foy "193 "(chauffé, éclairé, climatisé, Wi-Fi et "194 "électroménagers inclus).",195 amenities=list(AMENITIES),196 details={"floor": floor,197 "contact": {"email": "location@lienard.ca",198 "phone": "418-808-8823"}},199 images=[plan_img] if plan_img else [],200 ))201 return listings202