Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/condos18.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/condos18.py : connecteur Condos Locatifs 1891# (condoslocatifs18.ca — 1195, 18e Rue, Limoilou, Québec, à deux pas de92# l'hôpital de l'Enfant-Jésus/CHU). One-pager maison rendu serveur : les93# prix sont affichés PAR TYPE d'unité (« 3 1/2 … À partir de 1200$ par94# mois ») dans des onglets #s312/#s412/#s512, chacun listant ses variantes95# de plans (Emplacement / Description / Superficie). Une annonce par type96# d'unité — la granularité du site — avec la fourchette de superficies des97# variantes, les plans (lightbox) et les photos du modèle en galerie.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type, parse_price106from .base import BaseConnector107108BASE = "https://condoslocatifs18.ca"109PAGE_URL = f"{BASE}/"110111ADDRESS = "1195, 18e Rue, Québec, G1J 0G5"112SECTOR = "Limoilou"113CITY = "Québec"114LAT, LNG = 46.835710, -71.227340 # marqueur Google Maps de la page115116AREA_RE = re.compile(r"Superficie\s*:\s*([\d\s]+)\s*pi", re.I)117FLOOR_RE = re.compile(r"Emplacement\s*:\s*([^\n<]+)", re.I)118DESC_RE = re.compile(r"Description\s*:\s*([^\n<]+)", re.I)119# photos du modèle / de l'immeuble (hors icônes, logos et plans)120PHOTO_RE = re.compile(r'(?:src|href)="(/images/condos-locatifs-18/'121 r'(?:modele-condo-interieur-exterieur/big/[^"]+|'122 r"condo-a-louer/\d+[^\"]*|img-exterieur[^\"]*))\"", re.I)123124125class Condos18Connector(BaseConnector):126 source_id = "condos18"127 request_delay = 0.6128129 def fetch(self) -> list[Listing]:130 listings: list[Listing] = []131 html = self.get(PAGE_URL).text132 soup = BeautifulSoup(html, "html.parser")133134 # photos communes de l'immeuble/du modèle135 photos = [BASE + u for u in dict.fromkeys(PHOTO_RE.findall(html))136 if not re.search(r"_tn|tn\.png|map-", u, re.I)][:15]137138 details_common: dict = {}139 m = re.search(r'href="mailto:([^"?]+)"', html)140 contact = {"email": m.group(1).strip().lower()} if m else {}141 m = re.search(r'href="tel:\+?1?[\s.]*(\d{3})[\s.]*(\d{3})[\s.]*(\d{4})"',142 html)143 if not m:144 m = re.search(r"\b(418)[\s.]+(\d{3})[\s.]+(\d{4})\b",145 soup.get_text(" ", strip=True))146 if m:147 contact["phone"] = f"{m.group(1)}-{m.group(2)}-{m.group(3)}"148 if contact:149 details_common["contact"] = contact150151 # onglets prix par type : bouton « 3 1/2 » (id="#s312") + « À partir152 # de 1200$ par mois », puis panneau <div id="s312"> avec les variantes153 for btn in soup.select("a.bouton.appart"):154 try:155 unit_type = normalize_unit_type(btn.get_text(strip=True))156 if not unit_type:157 continue158 pane_id = (btn.get("id") or "").lstrip("#")159 info = btn.find_next(class_="info_cachee")160 price_label = re.sub(161 r"\s+", " ", info.get_text(" ", strip=True)) if info else ""162 price = parse_price(price_label)163164 # variantes de plans du panneau correspondant165 pane = soup.find("div", id=pane_id) if pane_id else None166 areas: list[float] = []167 floors: list[str] = []168 desc = ""169 plans: list[str] = []170 if pane is not None:171 pane_html = str(pane)172 for a in AREA_RE.findall(pane_html):173 try:174 v = float(a.replace(" ", "").replace(" ", ""))175 if 200 <= v <= 3000:176 areas.append(v)177 except ValueError:178 continue179 floors = [f.strip() for f in FLOOR_RE.findall(pane_html)]180 dm = DESC_RE.search(pane_html)181 if dm:182 desc = dm.group(1).strip().rstrip(".") + "."183 plans = [BASE + u for u in dict.fromkeys(184 re.findall(r'href="(/images/[^"]*plan-big[^"]+)"',185 pane_html, re.I))]186187 amenities: list[str] = []188 if areas:189 lo, hi = min(areas), max(areas)190 amenities.append(191 f"Superficies : {int(lo)} pi²" if lo == hi192 else f"Superficies : {int(lo)} à {int(hi)} pi²")193 if floors:194 amenities.append(f"Emplacement : {floors[0]}")195 amenities += ["Ascenseur", "Climatisation murale",196 "Insonorisation supérieure",197 "Stationnement intérieur (option)", "Gym"]198199 listings.append(Listing(200 source=self.source_id,201 external_id=f"type-{unit_type.replace('½', '.5')}",202 url=PAGE_URL,203 title=f"{unit_type} — Condos Locatifs 18",204 address=ADDRESS,205 sector=SECTOR,206 city=CITY,207 unit_type=unit_type,208 price=price,209 price_label=price_label,210 area_sqft=min(areas) if areas else None,211 description=desc,212 amenities=amenities,213 details=dict(details_common),214 images=photos + plans,215 lat=LAT,216 lng=LNG,217 ))218 except Exception:219 continue220 return listings221