Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/celeste.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/celeste.py : connecteur CÉLESTE LaSalle (louerceleste.com)91# 815, rue Gagné, LaSalle (Montréal) — deux immeubles (A et B), 3½ à 5½.92# WordPress/Avada : chaque unité est un « avada_portfolio » exposé par la93# REST API (/wp-json/wp/v2/avada_portfolio, ~452 items FR+EN). Taxonomie94# portfolio_category : 62/64/66 = types FR (3½/4½/5½), 60 = loué,95# 58 = disponible. Candidats = items FR marqués disponibles ou non marqués96# loués ; la fiche fait foi (« Disponibilité: LOUÉ » -> exclu). La fiche97# fournit grandeur, étage, salles de bain, « Loyer : à partir de $…/mois »,98# détails/équipements et la galerie. Inventaire souvent nul (immeubles99# pleins) : le connecteur retourne alors une liste vide, ce qui est correct.100# -----------------------------------------------------------------------------101from __future__ import annotations102103import re104105from bs4 import BeautifulSoup106107from ..schema import Listing108from .base import BaseConnector109110BASE = "https://louerceleste.com"111API = f"{BASE}/wp-json/wp/v2/avada_portfolio"112ADDRESS = "815, rue Gagné, LaSalle, Montréal, QC"113114CAT_TYPES_FR = {62: "3½", 64: "4½", 66: "5½"} # types (taxonomie FR)115CAT_LOUE = 60 # marqué loué116CAT_DISPO = 58 # marqué disponible117118_PRICE_RE = re.compile(r"Loyer\s*:?\s*\|?\s*à partir de\s*\$?\s*([\d\s,]+)"119 r"\s*/\s*mois", re.I)120_FLOOR_RE = re.compile(r"Étage\s*:\s*\|?\s*(\d+)", re.I)121_BATH_RE = re.compile(r"salles? de bain\s*:\s*\|?\s*([\d.]+)", re.I)122_SIZE_RE = re.compile(r"Grandeur\s*:\s*\|?\s*(\d\s*½|\d\s*1/2)", re.I)123_LOUE_RE = re.compile(r"Disponibilité\s*:\s*\|?\s*LOU[ÉE]", re.I)124_IMG_RE = re.compile(125 r'https://louerceleste\.com/wp-content/uploads/[^"\'\s\\)]+?'126 r'\.(?:jpg|jpeg|png|webp)', re.I)127_SKIP_IMG = re.compile(r"logo|icon|favicon|-\d{2,4}x\d{2,4}\.", re.I)128129130class CelesteConnector(BaseConnector):131 source_id = "celeste"132 request_delay = 0.6133 max_candidates = 40 # garde-fou de crawl des fiches134 max_images = 20135136 # -- inventaire REST (toutes les unités, FR + EN) ---------------------------137 def _portfolio_items(self) -> list[dict]:138 items: list[dict] = []139 for page in range(1, 12):140 try:141 batch = self.get(API, params={142 "per_page": "100", "page": str(page),143 "_fields": "id,link,title,portfolio_category",144 }).json()145 except Exception: # HTTP 400 = fin de pagination WP146 break147 if not isinstance(batch, list) or not batch:148 break149 items.extend(batch)150 return items151152 def fetch(self) -> list[Listing]:153 listings: list[Listing] = []154 count = 0155 for it in self._portfolio_items():156 try:157 cats = set(it.get("portfolio_category") or [])158 unit_type = next((t for c, t in CAT_TYPES_FR.items()159 if c in cats), "")160 if not unit_type:161 continue # item EN ou hors taxonomie des types162 # candidat = marqué disponible, ou pas explicitement loué163 if CAT_DISPO not in cats and CAT_LOUE in cats:164 continue165 if count >= self.max_candidates:166 break167 count += 1168 lst = self._parse_unit(it, unit_type)169 if lst is not None:170 listings.append(lst)171 except Exception:172 continue173 return listings174175 # -- fiche de l'unité : la mention « LOUÉ » fait foi -------------------------176 def _parse_unit(self, it: dict, unit_type: str) -> Listing | None:177 url = it.get("link") or ""178 title = re.sub(r"<[^>]+>", "",179 (it.get("title") or {}).get("rendered") or "").strip()180 if not url:181 return None182 html = self.get(url).text183 soup = BeautifulSoup(html, "html.parser")184 txt = soup.get_text(" | ", strip=True)185186 if _LOUE_RE.search(txt):187 return None # loué malgré la taxonomie188189 price = None190 price_label = ""191 pm = _PRICE_RE.search(txt)192 if pm:193 digits = re.sub(r"[^\d]", "", pm.group(1))194 if digits:195 price = float(digits)196 price_label = f"À partir de {int(price)} $/mois"197 if price is not None and not (100 <= price <= 20000):198 price = None199200 bathrooms = None201 bm = _BATH_RE.search(txt)202 if bm:203 try:204 bathrooms = float(bm.group(1))205 except ValueError:206 bathrooms = None207208 details: dict = {}209 fm = _FLOOR_RE.search(txt)210 if fm:211 details["floor"] = fm.group(1)212 sm = _SIZE_RE.search(txt)213 if sm: # ex. « 3 ½ » (confirme le type)214 unit_type = sm.group(1).replace(" ", "").replace("1/2", "½")215216 # détails / équipements (listes de la fiche)217 amenities: list[str] = []218 for li in soup.select(".fusion-text li, .post-content li"):219 t = li.get_text(" ", strip=True)220 if t and len(t) < 80 and t not in amenities:221 amenities.append(t)222 amenities = amenities[:25]223224 images: list[str] = []225 for u in _IMG_RE.findall(html):226 if _SKIP_IMG.search(u):227 continue228 if u not in images:229 images.append(u)230 images = images[: self.max_images]231232 return Listing(233 source=self.source_id,234 external_id=str(it.get("id")),235 url=url,236 title=title or f"CÉLESTE — {unit_type}",237 address=ADDRESS,238 sector="LaSalle",239 city="Montréal",240 unit_type=unit_type,241 bathrooms=bathrooms,242 price=price,243 price_label=price_label,244 availability="Disponible",245 description="",246 amenities=amenities,247 details=details,248 images=images,249 )250