Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/square_philippe.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/square_philippe.py : connecteur Square Philippe (squarephilippe.com)91# Complexe locatif neuf de Gatineau (secteur est, J8P) — 4 immeubles92# (25 rue du Galion, 75/91/115 rue Campagnard), 119 unités au total.93# WordPress rendu serveur : /a-louer/unites/ liste les unités DISPONIBLES en94# cartes `.theUnits` (data-rel = « 1 chambre »/« 2 chambres ») avec bandeau95# adresse (`.coin span`), prix (`.prix` « 1 700$ »), numéro d'unité + pi²96# (`.infoAll`), étage + chambres + « Disponible » (`.info2`) et photo du plan.97# external_id = <immeuble en slug>-<numéro d'unité> — stable par unité.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, strip_accents106from .base import BaseConnector107108BASE = "https://squarephilippe.com"109LIST_URL = f"{BASE}/a-louer/unites/"110111PRICE_RE = re.compile(r"([\d\s ]{3,7})\$")112UNIT_NO_RE = re.compile(r"Unité\s*(\w+)", re.I)113AREA_RE = re.compile(r"Total\s*:\s*([\d\s ]+)\s*pi", re.I)114BEDS_RE = re.compile(r"(\d+)\s*chambres?", re.I)115FLOOR_RE = re.compile(r"(Rez-de-chaussée|\d+e\s*étage)", re.I)116117118def _slug(text: str) -> str:119 s = strip_accents(text.lower())120 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")121122123def _num(txt: str) -> float | None:124 n = re.sub(r"[\s ]", "", txt or "")125 try:126 return float(n)127 except ValueError:128 return None129130131class SquarePhilippeConnector(BaseConnector):132 source_id = "square_philippe"133 request_delay = 0.8134135 def fetch(self) -> list[Listing]:136 soup = BeautifulSoup(self.get(LIST_URL).text, "html.parser")137 listings: dict[str, Listing] = {}138 for card in soup.select(".theUnits"):139 try:140 self._parse_card(card, listings)141 except Exception:142 continue143 return list(listings.values())144145 def _parse_card(self, card, listings: dict[str, Listing]) -> None:146 coin = card.select_one(".coin span")147 building = re.sub(r"\s+", " ", coin.get_text(" ", strip=True)) \148 if coin else ""149 info = card.select_one(".infoAll")150 info_txt = re.sub(r"\s+", " ", info.get_text(" ", strip=True)) \151 if info else ""152 m = UNIT_NO_RE.search(info_txt)153 if not building or not m:154 return155 unit_no = m.group(1)156 ext_id = f"{_slug(building)}-{unit_no}"157 if ext_id in listings:158 return159160 price = None161 price_label = ""162 prix_el = card.select_one(".prix")163 if prix_el:164 price_label = re.sub(r"\s+", " ", prix_el.get_text(" ", strip=True))165 pm = PRICE_RE.search(price_label)166 if pm:167 price = _num(pm.group(1))168169 area = None170 am = AREA_RE.search(info_txt)171 if am:172 area = _num(am.group(1))173174 info2 = card.select_one(".info2")175 info2_txt = re.sub(r"\s+", " ", info2.get_text(" ", strip=True)) \176 if info2 else ""177 bedrooms = None178 bm = BEDS_RE.search(info2_txt + " " + (card.get("data-rel") or ""))179 if bm:180 bedrooms = float(bm.group(1))181 details: dict = {}182 fm = FLOOR_RE.search(info2_txt)183 if fm:184 details["floor"] = fm.group(1)185186 availability = ""187 av = card.find(string=re.compile(r"Disponible|Loué", re.I))188 if av:189 availability = re.sub(r"\s+", " ", str(av)).strip()190 if re.search(r"lou[ée]", availability, re.I):191 return # unité déjà louée : on saute192193 images: list[str] = []194 for im in card.select("img[src]"):195 u = im["src"]196 if not u.startswith("http"):197 u = BASE + u198 if u not in images and not re.search(r"logo|icon", u, re.I):199 images.append(u)200201 desc_bits = [b for b in (details.get("floor", ""),202 f"{int(area)} pi²" if area else "") if b]203 listings[ext_id] = Listing(204 source=self.source_id,205 external_id=ext_id,206 url=f"{LIST_URL}#{ext_id}",207 title=f"Unité {unit_no} — {building}",208 address=f"{building}, Gatineau",209 sector="",210 city="Gatineau",211 bedrooms=bedrooms,212 price=price,213 price_label=price_label,214 availability=availability,215 area_sqft=area,216 description=" | ".join(desc_bits),217 details=details,218 images=images,219 )220