Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/lacite.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0913# Last Modified : 2026-08-0914#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/lacite.py : connecteur La Cité Gatineau (lacitegatineau.com)91# Tour de 200+ condos locatifs au 700, boulevard du Carrefour, Gatineau92# (Adam Real Estate). WordPress/Elementor + Toolset Views : la page93# /plans-des-appartements/ liste 14 TYPES d'unités (nom, chambres,94# superficie, plan) et chaque fiche /type-unite/<slug>/ publie les95# salles de bain, les superficies (unité/balcon/totale) et surtout la96# liste « APPARTEMENT(S) SIMILAIRE(S) » = numéros d'appartements97# actuellement offerts (« A – 702 ») ou « Aucun appartement disponible ».98# -> une annonce par APPARTEMENT LISTÉ DISPONIBLE (uid = numéro d'unité).99# AUCUN prix n'est publié nulle part -> price None, rien d'inventé.100# ⚠ robots.txt : « Crawl-delay: 10 » -> request_delay = 10 s ; une sync =101# 1 + 14 requêtes ≈ 2,5 min. Pas de cache détail : la disponibilité vit102# sur les fiches type et doit rester fraîche.103# -----------------------------------------------------------------------------104from __future__ import annotations105106import re107108from bs4 import BeautifulSoup109110from ..schema import Listing, normalize_unit_type, strip_accents111from .base import BaseConnector112113BASE = "https://lacitegatineau.com"114LIST_URL = f"{BASE}/plans-des-appartements/"115ADDRESS = "700, boulevard du Carrefour, Gatineau"116117118def _slugify(s: str) -> str:119 s = strip_accents(s.lower())120 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")121122123class LaCiteConnector(BaseConnector):124 source_id = "lacite"125 request_delay = 10.0 # robots.txt : Crawl-delay: 10126 max_types = 20127128 # -- fiche type ---------------------------------------------------------------129 def _parse_type(self, url: str) -> dict:130 """Salles de bain, superficies et numéros d'appartements offerts."""131 soup = BeautifulSoup(self.get(url).text, "html.parser")132 text = soup.get_text("\n", strip=True)133 out: dict = {"units": [], "baths": None, "sqft": None,134 "sqft_balcony": None, "sqft_total": None, "pdf": ""}135136 m = re.search(r"(\d+)\s*\n?\s*salle\(s\) de bain", text)137 if m:138 out["baths"] = int(m.group(1))139 for label, key in (("SUPERFICIE :", "sqft"),140 ("SUPERFICIE BALCON :", "sqft_balcony"),141 ("SUPERFICIE TOTALE :", "sqft_total")):142 mm = re.search(rf"{re.escape(label)}\s*\n?\s*([\d\s,]+)\s*pi", text)143 if mm:144 try:145 v = float(mm.group(1).replace(" ", "").replace(",", ""))146 if 40 <= v <= 20000:147 out[key] = v148 except ValueError:149 pass150151 # « APPARTEMENT(S) SIMILAIRE(S) : A – 702 … » jusqu'aux chambres152 mm = re.search(r"SIMILAIRE\(S\)\s*:?\s*\n(.*?)\n\d+\s*\n?chambre",153 text, re.S)154 if mm and not re.search(r"(?i)aucun appartement", mm.group(1)):155 for seg in mm.group(1).split("\n"):156 seg = re.sub(r"\s+", " ", seg).strip()157 if re.match(r"^[A-Z]\s*[–-]\s*\d+$", seg):158 out["units"].append(seg)159160 a = soup.find("a", href=re.compile(r"\.pdf$", re.I))161 if a:162 out["pdf"] = a["href"]163 return out164165 # -- fetch -----------------------------------------------------------------166 def fetch(self) -> list[Listing]:167 soup = BeautifulSoup(self.get(LIST_URL).text, "html.parser")168 listings: dict[str, Listing] = {}169 items = soup.select("ul.wpv-loop > li")[: self.max_types]170 for li in items:171 try:172 a = li.select_one("a[href*='/type-unite/']")173 if not a:174 continue175 type_url = a["href"]176 type_name = re.sub(r"\s+", " ", a.get_text(" ", strip=True))177 # « 1 chambre(s) – 742 pi² » sous le titre178 li_text = re.sub(r"\s+", " ", li.get_text(" ", strip=True))179 beds = None180 mb = re.search(r"(\d+)\s*chambre", li_text)181 if mb:182 beds = int(mb.group(1))183 img = li.select_one("img[data-src], img[src^='http']")184 plan_img = (img.get("data-src") or img.get("src")185 if img else "") or ""186187 info = self._parse_type(type_url)188 for unit in info["units"]:189 num = re.sub(r"\s*[–-]\s*", "-", unit)190 ext = _slugify(num)191 if not ext or ext in listings:192 continue193 # les chaînes « 502-702-1102-1702 » du nom de type194 # ressemblent à des téléphones pour l'extracteur commun :195 # séparateur neutre « · » dans la description196 safe_name = re.sub(r"(\d)-(?=\d)", r"\1·", type_name)197 desc_bits = [f"Type {safe_name}"]198 if info.get("sqft_balcony"):199 desc_bits.append(200 f"balcon {info['sqft_balcony']:.0f} pi²")201 if info.get("sqft_total"):202 desc_bits.append(203 f"superficie totale {info['sqft_total']:.0f} pi²")204 details: dict = {}205 if info.get("baths"):206 details["bathrooms"] = info["baths"]207 if info.get("pdf"):208 details["floorplan_pdf"] = info["pdf"]209210 listings[ext] = Listing(211 source=self.source_id,212 external_id=ext,213 url=type_url,214 title=f"La Cité Gatineau — {unit}",215 address=ADDRESS,216 sector="",217 city="Gatineau",218 unit_type=(normalize_unit_type(f"{beds} chambres")219 if beds else ""),220 price=None, # aucun prix publié sur le site221 price_label="",222 # le site liste l'unité sous « APPARTEMENT(S)223 # SIMILAIRE(S) » sans date : rien d'inventé224 availability="",225 area_sqft=info.get("sqft"),226 description=" — ".join(desc_bits)[:600],227 details=details,228 images=[plan_img] if plan_img.startswith("http") else [],229 )230 except Exception:231 continue232 return list(listings.values())233