SPB Git

Repository Public

aalto.py 9.6 KB 235 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/aalto.py10# Module           : louka11# Repository       : https://git.spboucher.ai/lou-ka12# Created          : 2026-08-0913# Last Modified    : 2026-08-2714#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/aalto.py : connecteur Aalto Suites (aaltosuites.ca — Zibi, Hull)91#   Tours locatives Aalto et Aalto II de Dream, premiers immeubles92#   résidentiels du quartier Zibi (rive québécoise, secteur Hull de93#   Gatineau — 10, rue Jos-Montferrand, J8X 0A6, adresse publiée par le94#   site). Site RentCafe/Yardi (gabarit « ritz ») derrière Cloudflare (40395#   en direct) : rendu JS via Scrapfly comme realstar.py/osgoode.py (ex-Firecrawl).96#   La page /floorplans (française) publie une carte par PLAN : nom97#   (« Aalto II | S2 »), typologie (« studio / 1 SdB »), superficie en pc,98#   prix « à partir de $1,520.00/mois » et image du plan -> une annonce par99#   plan. Aucun décompte d'unités disponibles publié -> availability vide.100#   NB : le Crawl-delay 10 de zibi.ca ne s'applique qu'à zibi.ca (jamais101#   requêté ici) ; aaltosuites.ca n'impose aucun délai (2 rendus par sync).102# -----------------------------------------------------------------------------103from __future__ import annotations104105import re106107from bs4 import BeautifulSoup108109from ..schema import Listing, normalize_unit_type, strip_accents110from .base import BaseConnector111112BASE = "https://www.aaltosuites.ca"113FLOORPLANS_URL = f"{BASE}/floorplans"114115# adresse du complexe publiée par le site (lien Google Maps du pied de page)116ADDRESS = "10, rue Jos-Montferrand, Gatineau"117118119def _slugify(s: str) -> str:120    s = strip_accents(s.lower())121    return re.sub(r"[^a-z0-9]+", "-", s).strip("-")122123124class AaltoConnector(BaseConnector):125    source_id = "aalto"126    request_delay = 2.0127    max_plans = 60128129    # -- rendu JS avec attente (Cloudflare + SPA RentCafe) — Scrapfly ----------130    # (migré de Firecrawl le 2026-08-27 ; retry + échec honnête dans131    #  BaseConnector.get_rendered, que les fixtures monkeypatchent)132    def _rendered(self, url: str, wait_ms: int = 9000) -> str:133        return self.get_rendered(url, wait_ms)134135    @staticmethod136    def _unit_type(label: str) -> str:137        """« studio / 1 SdB » -> Studio ; « 2 Chambres à coucher / 2 SdB »138        ou « 1 chambre / 1 SdB » -> N½ par la couche commune."""139        t = strip_accents(label.lower())140        if "studio" in t:141            return "Studio"142        m = re.match(r"^(\d+)\s*chambre", t)143        if m:144            return normalize_unit_type(f"{m.group(1)} chambres")145        return ""146147    # -- fetch -----------------------------------------------------------------148    def fetch(self) -> list[Listing]:149        # description du complexe : premier paragraphe substantiel de l'accueil150        blurb = ""151        try:152            home = BeautifulSoup(self._rendered(BASE + "/", 8000),153                                 "html.parser")154            for p in home.find_all("p"):155                t = re.sub(r"\s+", " ", p.get_text(" ", strip=True))156                if len(t) > 100:157                    blurb = t[:600]158                    break159        except Exception:160            pass161162        html = self._rendered(FLOORPLANS_URL, 10000)163        soup = BeautifulSoup(html, "html.parser")164        cards = soup.select("div[id^='fp-container-']")165        if not cards:   # rendu incomplet : une seconde chance166            html = self._rendered(FLOORPLANS_URL, 15000)167            soup = BeautifulSoup(html, "html.parser")168            cards = soup.select("div[id^='fp-container-']")169170        listings: dict[str, Listing] = {}171        for card in cards[: self.max_plans]:172            try:173                h2 = card.select_one("h2.property-title")174                name = re.sub(r"\s+", " ",175                              h2.get_text(" ", strip=True)) if h2 else ""176                if not name:177                    continue178                ext = _slugify(name)179                if not ext or ext in listings:180                    continue181182                # « studio / 1 SdB » ● « 483 pc »183                typo = sqft_txt = ""184                for span in card.select(".property-details span"):185                    t = re.sub(r"\s+", " ", span.get_text(" ", strip=True))186                    if re.search(r"(?i)sdb|chambre|studio", t):187                        typo = typo or t188                    elif re.search(r"\d\s*pc\b", t):189                        sqft_txt = sqft_txt or t190                area = None191                m = re.search(r"([\d\s,]{2,7})\s*pc", sqft_txt)192                if m:193                    v = float(m.group(1).replace(" ", "").replace(",", ""))194                    if 80 <= v <= 20000:195                        area = v196197                # « à partir de $1,520.00 /mois »198                price = None199                price_label = ""200                amt = card.select_one(".pricing-amount")201                if amt:202                    raw = amt.get_text(" ", strip=True)203                    pm = re.search(r"\$?([\d,]+)(?:\.\d{2})?", raw)204                    if pm:205                        price = float(pm.group(1).replace(",", ""))206                        price_label = f"à partir de {raw}/mois"207208                img_el = card.select_one("img[src*='resource.rentcafe.com']")209                images = [img_el["src"]] if img_el and img_el.get("src") else []210211                building = name.split("|")[0].strip()212                desc_bits = [x for x in [typo, sqft_txt, building] if x]213                if blurb:214                    desc_bits.append(blurb)215216                listings[ext] = Listing(217                    source=self.source_id,218                    external_id=ext,219                    url=FLOORPLANS_URL,220                    title=name,221                    address=ADDRESS,222                    sector="Hull",       # quartier Zibi, rive québécoise223                    city="Gatineau",224                    unit_type=self._unit_type(typo),225                    price=price,226                    price_label=price_label,227                    availability="",     # aucun décompte d'unités publié228                    area_sqft=area,229                    description=" — ".join(desc_bits)[:900],230                    images=images,231                )232            except Exception:233                continue234        return list(listings.values())235
Files main
Menu

Theme