SPB Git

Repository Public

signature_boisbriand.py 8.5 KB 222 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/signature_boisbriand.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/signature_boisbriand.py : connecteur Signature Boisbriand91#   (signatureboisbriand.com) — projet locatif au 1040-1050, rue des92#   Francs-Bourgeois, Boisbriand (Faubourg Boisbriand, ~266 unités).93#   WordPress + FacetWP rendu serveur : /unites-disponibles/ liste des lignes94#   .unit-row (numéro #1040-101, pièces, étage, superficie, prix « à partir95#   de », disponibilité, plan PDF) paginées via le paramètre ?_paged=N96#   (15 lignes/page). On ne garde que les unités NON « Unité louée ».97#   Granularité : unité.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type106from .base import BaseConnector107108BASE = "https://signatureboisbriand.com"109UNITS_URL = f"{BASE}/unites-disponibles/"110MAX_PAGES = 30111112ADDRESS = "1040, rue des Francs-Bourgeois, Boisbriand"113CITY = "Boisbriand"114115PRICE_RE = re.compile(r"(\d[\d\s,]*)\s*\$")116IMG_RE = re.compile(117    r"https://signatureboisbriand\.com/wp-content/uploads/"118    r"[^\"'\s\\]+\.(?:jpe?g|png|webp)", re.I)119SKIP_IMG_RE = re.compile(r"logo|favicon|icon|-\d{2,4}x\d{2,4}\.", re.I)120121122class SignatureBoisbriandConnector(BaseConnector):123    source_id = "signature_boisbriand"124    request_delay = 0.6125    max_images = 10126127    def _site_images(self) -> list[str]:128        """Photos du projet (page d'accueil) — les lignes n'ont qu'un plan PDF."""129        try:130            html = self.get(f"{BASE}/").text131        except Exception:132            return []133        return [u for u in dict.fromkeys(IMG_RE.findall(html))134                if not SKIP_IMG_RE.search(u)][: self.max_images]135136    @staticmethod137    def _txt(row, sel: str) -> str:138        el = row.select_one(sel)139        return re.sub(r"\s+", " ", el.get_text(" ", strip=True)) if el else ""140141    def fetch(self) -> list[Listing]:142        images = self._site_images()143        listings: list[Listing] = []144        seen: set[str] = set()145146        for page in range(1, MAX_PAGES + 1):147            url = UNITS_URL if page == 1 else f"{UNITS_URL}?_paged={page}"148            try:149                html = self.get(url).text150            except Exception:151                break152            soup = BeautifulSoup(html, "html.parser")153            rows = soup.select(".unit-row")154            if not rows:155                break156157            new_on_page = 0158            for row in rows:159                num = self._txt(row, ".unit-number__text").lstrip("#").strip()160                if not num or num in seen:161                    continue162                seen.add(num)163                new_on_page += 1164165                availability = self._txt(row, ".unit-availability__text")166                if re.search(r"lou[ée]", availability, re.I):167                    continue                       # « Unité louée »168169                unit_type = normalize_unit_type(170                    self._txt(row, ".unit-room__text"))171                floor = self._txt(row, ".unit-floor__text")172173                area = None174                m = re.search(r"(\d[\d\s]*)\s*pi",175                              self._txt(row, ".unit-area__text"))176                if m:177                    try:178                        v = float(m.group(1).replace(" ", "").replace(" ", ""))179                        if 100 <= v <= 10000:180                            area = v181                    except ValueError:182                        pass183184                price = None185                price_label = ""186                m = PRICE_RE.search(self._txt(row, ".unit-price__text"))187                if m:188                    try:189                        val = float(m.group(1).replace(" ", "")190                                    .replace(" ", "").replace(",", ""))191                        if 300 <= val <= 20000:192                            price = val193                            price_label = f"à partir de {int(val)}$"194                    except ValueError:195                        pass196197                imgs = list(images)198                plan = row.select_one('.unit-plan a[href$=".pdf"]')199                details: dict = {}200                if plan is not None:201                    details["floor_plan"] = plan["href"]202203                listings.append(Listing(204                    source=self.source_id,205                    external_id=num,206                    url=UNITS_URL,207                    title=f"Signature Boisbriand — Unité #{num}",208                    address=ADDRESS,209                    city=CITY,210                    unit_type=unit_type,211                    price=price,212                    price_label=price_label,213                    availability=availability or "Disponible",214                    area_sqft=area,215                    description=f"Unité #{num}, {floor}" if floor else "",216                    details=details,217                    images=imgs,218                ))219            if new_on_page == 0:220                break221        return listings222
Files main
Menu

Theme