SPB Git

Repository Public

grandeur_natura.py 7.8 KB 202 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/grandeur_natura.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/grandeur_natura.py : connecteur Grandeur Natura91#   (grandeurnatura.ca, Groupe Mathieux) — 6-plex locatifs neufs au 1199,92#   rue Marcel-de la Sablonnière, Terrebonne (Urbanova), J0N 1H0.93#   WordPress/Bootstrap rendu serveur : la page d'accueil décrit chaque94#   typologie dans un bloc « Unité locative - Appartement n ½ » (SDB,95#   chambres, garage, carrousel de photos par unité, plan PDF commun).96#   Les blocs « Maisons de prestige » sont des maisons à VENDRE : exclus.97#   Aucun prix publié (jamais inventé). Granularité TYPOLOGIE (3½/4½/5½).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing106from .base import BaseConnector107108BASE = "https://grandeurnatura.ca"109ADDRESS = "1199, rue Marcel-de la Sablonnière"110CITY = "Terrebonne"111SECTOR = "Urbanova"112113UNIT_H3_RE = re.compile(r"^Unité locative\s*[–-]\s*Appartement\s*([2-6])\s*½")114SDB_RE = re.compile(r"(\d)\s*SDB", re.I)115BEDS_RE = re.compile(r"(\d)\s*chambres?\b", re.I)116GARAGE_RE = re.compile(r"(Garage[^.\n|]{0,40})", re.I)117IMG_OK_RE = re.compile(r"\.(?:jpe?g|png|webp)$", re.I)118119120class GrandeurNaturaConnector(BaseConnector):121    source_id = "grandeur_natura"122    request_delay = 0.8123124    def fetch(self) -> list[Listing]:125        listings: list[Listing] = []126        try:127            html = self.get(BASE + "/").text128        except Exception:129            return listings130        soup = BeautifulSoup(html, "html.parser")131        for h3 in soup.select("h3"):132            title = h3.get_text(" ", strip=True)133            m = UNIT_H3_RE.match(title)134            if not m:135                continue                       # « Maisons de prestige » = vente136            n = m.group(1)137            unit_type = f"{n}½"138            row = h3.find_parent("div", class_="row") or h3.parent139            text = row.get_text(" | ", strip=True)140141            baths = beds = None142            bm = SDB_RE.search(text)143            if bm:144                baths = float(bm.group(1))145            cm = BEDS_RE.search(text)146            if cm:147                beds = float(cm.group(1))148            amenities: list[str] = []149            gm = GARAGE_RE.search(text)150            if gm:151                amenities.append(gm.group(1).strip())152153            # phrase descriptive du bloc (le premier paragraphe substantiel)154            desc = ""155            for p in row.select("p"):156                t = p.get_text(" ", strip=True)157                if len(t) > 40:158                    desc = t159                    break160161            # photos du carrousel de l'unité (variantes @2x/redimensionnées162            # dédupliquées ; logos exclus)163            images: list[str] = []164            for img in row.select("img"):165                src = img.get("src") or img.get("data-src") or ""166                if src.startswith("/"):167                    src = BASE + src168                if not src.startswith("http") or not IMG_OK_RE.search(src):169                    continue170                if re.search(r"logo|icon|@2x|-\d+x\d+\.|-scaled", src, re.I):171                    continue172                if src not in images:173                    images.append(src)174175            details: dict = {"building": "Grandeur Natura"}176            plan = row.select_one('a[href$=".pdf"]')177            if plan is not None:178                href = plan.get("href") or ""179                details["plan_pdf"] = (BASE + href) if href.startswith("/") \180                    else href181182            listings.append(Listing(183                source=self.source_id,184                external_id=f"unite-{n}.5",    # typologie : stable185                url=BASE + "/",186                title=f"Grandeur Natura — {unit_type}",187                address=ADDRESS,188                sector=SECTOR,189                city=CITY,190                unit_type=unit_type,191                bedrooms=beds,192                bathrooms=baths,193                price=None,194                price_label="",195                availability="Sur demande",196                description=desc[:2000],197                amenities=amenities,198                details=details,199                images=images[:15],200            ))201        return listings202
Files main
Menu

Theme