SPB Git

Repository Public

san_leon.py 9.2 KB 229 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/san_leon.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/san_leon.py : connecteur San Leon (sanleon.ca)91#   Appartements locatifs neufs au Faubourg Boisbriand — 3230, avenue des92#   Grandes Tourelles, Boisbriand (phases 4 et 5, ~118 unités/phase).93#   Le site embarque Planpoint : l'API Next.js répond en JSON à94#   POST https://app.planpoint.io/api/groups/find95#   body {"namespace":"san-leon","hostName":"san-leon"} → projects[] → floors[]96#   → units[] (name, bedrooms, bathrooms, squareFeet, price — None en phase 5,97#   availability Available/Sold/Leased/Reserved, inclusions, images, delivery).98#   On ne garde que les unités « Available ». Granularité : unité.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103from datetime import date as _date104105from ..schema import Listing106107from .base import BaseConnector108109API_URL = "https://app.planpoint.io/api/groups/find"110API_BODY = {"namespace": "san-leon", "hostName": "san-leon"}111SITE_URL = "https://sanleon.ca/"112113ADDRESS = "3230, avenue des Grandes Tourelles, Boisbriand"114CITY = "Boisbriand"115116SLUG_RE = re.compile(r"[^a-z0-9]+")117# « 11/1/26 » ou « 2025-01-01 »118US_DATE_RE = re.compile(r"^(\d{1,2})/(\d{1,2})/(\d{2})$")119120121class SanLeonConnector(BaseConnector):122    source_id = "san_leon"123    request_delay = 0.6124    max_images = 10125126    @staticmethod127    def _unit_type(bedrooms: str | int | None) -> str:128        try:129            n = int(str(bedrooms).strip())130        except (TypeError, ValueError):131            return ""132        return f"{n + 2}½" if 0 < n < 5 else ("Studio" if n == 0 else "")133134    def fetch(self) -> list[Listing]:135        data = self.post(API_URL, json=API_BODY).json()136137        listings: list[Listing] = []138        seen: set[str] = set()139        for proj in data.get("projects") or []:140            pname = (proj.get("name") or "San Leon").strip()141            phase = pname.rsplit(" ", 1)[-1] if "Phase" in pname else ""142            pslug = SLUG_RE.sub("-", pname.lower()).strip("-")143            addr = (proj.get("address") or "").strip() or ADDRESS144145            for floor in proj.get("floors") or []:146                fname = str(floor.get("name") or "").strip()147                for u in floor.get("units") or []:148                    if (u.get("availability") or "").strip() != "Available":149                        continue150                    num = str(u.get("name") or "").strip()151                    if not num:152                        continue153                    ext_id = f"{pslug}-{num}"154                    if ext_id in seen:155                        continue156                    seen.add(ext_id)157158                    price = None159                    try:160                        v = float(u.get("price") or 0)161                        if 300 <= v <= 20000:162                            price = v163                    except (TypeError, ValueError):164                        pass165166                    area = None167                    try:168                        v = float(u.get("squareFeet") or 0)169                        if 100 <= v <= 10000:170                            area = v171                    except (TypeError, ValueError):172                        pass173174                    beds = None175                    try:176                        beds = float(int(str(u.get("bedrooms")).strip()))177                    except (TypeError, ValueError):178                        pass179                    baths = None180                    try:181                        baths = float(u.get("bathrooms") or 0) or None182                    except (TypeError, ValueError):183                        pass184185                    availability = "Disponible"186                    delivery = str(u.get("deliveryDate") or "").strip()187                    m = US_DATE_RE.match(delivery)188                    if m:189                        delivery = f"20{m.group(3)}-{int(m.group(1)):02d}" \190                                   f"-{int(m.group(2)):02d}"191                    if delivery and delivery > _date.today().isoformat():192                        availability = f"Disponible ({delivery})"193194                    amenities = [a.strip() for a in195                                 re.split(r"[,;]", u.get("inclusions") or "")196                                 if a.strip() and a.strip() != "*"]197198                    imgs = [i for i in199                            dict.fromkeys(u.get("images") or [])200                            if isinstance(i, str) and i.startswith("http")201                            ][: self.max_images]202203                    desc_bits = [204                        f"Unité {num}" + (f", étage {fname}" if fname else ""),205                        pname if phase else "",206                        f"Orientation {u['orientation']}"207                        if u.get("orientation") else "",208                        "Meublé" if u.get("furnished") else "",209                    ]210                    listings.append(Listing(211                        source=self.source_id,212                        external_id=ext_id,213                        url=SITE_URL,214                        title=f"{pname} — Unité {num}",215                        address=addr,216                        city=CITY,217                        unit_type=self._unit_type(u.get("bedrooms")),218                        bedrooms=beds,219                        bathrooms=baths,220                        price=price,221                        price_label="" if price else "Prix sur demande",222                        availability=availability,223                        area_sqft=area,224                        description=" — ".join(b for b in desc_bits if b),225                        amenities=amenities,226                        images=imgs,227                    ))228        return listings229
Files main
Menu

Theme