SPB Git

Repository Public

le_george.py 8.6 KB 232 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/le_george.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/le_george.py : connecteur Le George (legeorge.ca)91#   Tour locative au 1001, rue Lucien-L'Allier, centre-ville de Montréal92#   (Ville-Marie), studio à 5½. Site JS lourd : le sélecteur d'unités est un93#   iframe Planpoint — on interroge directement son API officielle94#   (POST app.planpoint.io/api/projects/find, namespace « le-george ») qui95#   retourne les 43 étages et ~730 unités. Seules les unités96#   « Available » sont annoncées (les « Leased »/« Unavailable » sont97#   exclues) : numéro, type (bedrooms « 1.5 » -> 1½, « Studio »), prix, pi²,98#   meublé, inclusions FR, galerie photos + plan de l'unité (PDF).99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from ..schema import Listing105from .base import BaseConnector106107SITE = "https://legeorge.ca"108API = "https://app.planpoint.io/api/projects/find"109NAMESPACE = "le-george"110ADDRESS = "1001, rue Lucien-L'Allier, Montréal, QC H3G 0G7"111112_HALF_RE = re.compile(r"^([1-6])[.,]5$")113114115class LeGeorgeConnector(BaseConnector):116    source_id = "le_george"117    request_delay = 0.6118    max_units = 200              # garde-fou (36 unités dispo à l'écriture)119120    def fetch(self) -> list[Listing]:121        proj = self.post(API, json={122            "namespace": NAMESPACE,123            "hostName": NAMESPACE,124        }).json()125        if not isinstance(proj, dict):126            return []127128        listings: list[Listing] = []129        count = 0130        for floor in proj.get("floors") or []:131            floor_name = str(floor.get("name") or "").strip()132            for u in floor.get("units") or []:133                try:134                    if (u.get("availability") or "") != "Available":135                        continue136                    if count >= self.max_units:137                        return listings138                    count += 1139                    listings.append(self._unit_listing(u, floor_name))140                except Exception:141                    continue142        return listings143144    def _unit_listing(self, u: dict, floor_name: str) -> Listing:145        number = str(u.get("name") or "").strip()146        ext = number or str(u.get("_id") or "")147148        # bedrooms Planpoint : « 1.5 » … « 5.5 » = type QC n½, ou « Studio »149        braw = str(u.get("bedrooms") or "").strip()150        unit_type = ""151        bedrooms = None152        hm = _HALF_RE.match(braw)153        if hm:154            n = int(hm.group(1))155            unit_type = f"{n}½"156            bedrooms = float(max(n - 2, 0))157        elif braw.lower() == "studio":158            unit_type = "Studio"159            bedrooms = 0.0160161        try:162            bathrooms = float(u.get("bathrooms")) if u.get("bathrooms") \163                else None164        except (TypeError, ValueError):165            bathrooms = None166167        try:168            price = float(u.get("price")) if u.get("price") else None169        except (TypeError, ValueError):170            price = None171        if price is not None and not (100 <= price <= 20000):172            price = None173174        try:175            sqft = float(u.get("squareFeet")) if u.get("squareFeet") else None176        except (TypeError, ValueError):177            sqft = None178179        # inclusions FR structurées (souvent vides)180        amenities: list[str] = []181        for inc in u.get("inclusionsArr") or []:182            t = (inc.get("fr") or inc.get("en") or "").strip()183            if t and t not in amenities:184                amenities.append(t)185        inc_txt = (u.get("inclusions") or "").strip()186        if inc_txt and inc_txt not in amenities:187            amenities.append(inc_txt)188        amenities = amenities[:25]189190        # photos de l'unité puis plans (layoutGallery)191        images = [x for x in (u.get("images") or []) if x][:20]192        for x in (u.get("layoutGallery") or []):193            if x and x not in images:194                images.append(x)195        images = images[:25]196197        details: dict = {}198        if floor_name:199            details["floor"] = floor_name200        plan = (u.get("downloadableAsset") or "").strip()201        if plan:202            details["floor_plan_pdf"] = plan203204        furnished = u.get("furnished") if isinstance(u.get("furnished"),205                                                     bool) else None206207        title = f"Le George — Unité {number}" if number else "Le George"208        if unit_type:209            title += f" ({unit_type})"210211        return Listing(212            source=self.source_id,213            external_id=f"u{ext}",214            url=f"{SITE}/choisir-mon-unite/",215            title=title,216            address=ADDRESS,217            sector="Ville-Marie",218            city="Montréal",219            unit_type=unit_type,220            bedrooms=bedrooms,221            bathrooms=bathrooms,222            price=price,223            price_label=f"{int(price)} $/mois" if price else "",224            availability="Disponible",225            area_sqft=sqft,226            furnished=furnished,227            description=(u.get("description") or "").strip()[:600],228            amenities=amenities,229            details=details,230            images=images,231        )232
Files main
Menu

Theme