SPB Git

Repository Public

central_rosemont.py 9.0 KB 241 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/central_rosemont.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/central_rosemont.py : connecteur Central Rosemont91#   (centralrosemont.com) — condos locatifs au 1295, rue des Carrières,92#   Rosemont (Montréal), au bord de la piste des Carrières. WordPress rendu93#   serveur : la page /appartements-disponibles/ affiche un bloc94#   div.bloc_unite_dispo[data-unite] par unité disponible — numéro, étage,95#   superficie (pi²), nombre de chambres, prix « 2465$/mois » (parfois vide),96#   date de disponibilité (« juin 2026 ») et plan PDF. Une annonce par unité,97#   id stable = numéro d'unité (data-unite).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing106from .base import BaseConnector107108BASE = "https://www.centralrosemont.com"109LIST_URL = f"{BASE}/appartements-disponibles/"110ADDRESS = "1295, rue des Carrières, Montréal, QC H2S 0E1"111112# Nombre de chambres -> type d'unité (convention QC : n½ = n-2 chambres)113_BED_TYPE = {0: "Studio", 1: "3½", 2: "4½", 3: "5½", 4: "6½"}114115_PRICE_RE = re.compile(r"([\d\s,]{3,7})\s*\$")116_SQFT_RE = re.compile(r"([\d\s]{2,6})\s*pi", re.I)117_FLOOR_RE = re.compile(r"Étage\s*(\d+)", re.I)118_IMG_RE = re.compile(119    r'https://(?:www\.)?centralrosemont\.com/wp-content/uploads/'120    r'[^"\'\s\\)]+?\.(?:jpg|jpeg|png|webp)', re.I)121_SKIP_IMG = re.compile(r"logo|icon|favicon|-\d{2,4}x\d{2,4}\.", re.I)122123124class CentralRosemontConnector(BaseConnector):125    source_id = "central_rosemont"126    request_delay = 0.6127    max_images = 20128129    def fetch(self) -> list[Listing]:130        html = self.get(LIST_URL).text131        soup = BeautifulSoup(html, "html.parser")132133        # galerie du projet (page disponibilités, sans logos/miniatures)134        images: list[str] = []135        for u in _IMG_RE.findall(html):136            if _SKIP_IMG.search(u):137                continue138            if u not in images:139                images.append(u)140        images = images[: self.max_images]141142        desc = ""143        meta = soup.find("meta", attrs={"name": "description"})144        if meta and meta.get("content"):145            desc = meta["content"].strip()[:600]146147        listings: list[Listing] = []148        for bloc in soup.select("div.bloc_unite_dispo[data-unite]"):149            try:150                lst = self._bloc_listing(bloc, desc, images)151                if lst is not None:152                    listings.append(lst)153            except Exception:154                continue155        return listings156157    def _bloc_listing(self, bloc, desc: str,158                      images: list[str]) -> Listing | None:159        unite = (bloc.get("data-unite") or "").strip()160        num_el = bloc.select_one(".numero_unite .value")161        number = (num_el.get_text(" ", strip=True) if num_el else unite)162        if not (unite or number):163            return None164165        # étage (« Étage 1 »)166        floor = ""167        fl_el = bloc.select_one(".etage_unite")168        if fl_el:169            fm = _FLOOR_RE.search(fl_el.get_text(" ", strip=True))170            if fm:171                floor = fm.group(1)172173        # superficie (« 800 pi² »)174        sqft = None175        sq_el = bloc.select_one(".superficie_unite p")176        if sq_el:177            sm = _SQFT_RE.search(sq_el.get_text(" ", strip=True))178            if sm:179                try:180                    sqft = float(re.sub(r"\s", "", sm.group(1)))181                except ValueError:182                    sqft = None183184        # chambres fermées -> type d'unité185        bedrooms = None186        unit_type = ""187        ch_el = bloc.select_one(".chambres_unite p")188        if ch_el:189            ct = re.sub(r"[^\d]", "", ch_el.get_text(" ", strip=True))190            if ct:191                bedrooms = float(ct)192                unit_type = _BED_TYPE.get(int(bedrooms), "")193194        # prix (« 2465$/mois », parfois vide « $/mois »)195        price = None196        price_label = ""197        px_el = bloc.select_one(".prix_unite .prix")198        if px_el:199            raw = px_el.get_text(" ", strip=True)200            pm = _PRICE_RE.search(raw)201            if pm:202                digits = re.sub(r"[^\d]", "", pm.group(1))203                if digits:204                    price = float(digits)205                    price_label = f"{int(price)} $/mois"206        if price is not None and not (100 <= price <= 20000):207            price = None208209        # date de disponibilité (« juin 2026 » ou vide = maintenant)210        availability = ""211        dt_el = bloc.select_one(".date_unite .date")212        if dt_el:213            availability = dt_el.get_text(" ", strip=True)214215        details: dict = {}216        if floor:217            details["floor"] = floor218        plan = bloc.select_one(".actions_unite a[href$='.pdf']")219        if plan and plan.get("href"):220            details["floor_plan_pdf"] = plan["href"]221222        return Listing(223            source=self.source_id,224            external_id=unite or number,225            url=LIST_URL,226            title=f"Central Rosemont — Unité {number}"227                  + (f" ({unit_type})" if unit_type else ""),228            address=ADDRESS,229            sector="Rosemont",230            city="Montréal",231            unit_type=unit_type,232            bedrooms=bedrooms,233            price=price,234            price_label=price_label,235            availability=availability or "Disponible",236            area_sqft=sqft,237            description=desc,238            details=details,239            images=list(images),240        )241
Files main
Menu

Theme