SPB Git

Repository Public

vi_laval.py 7.3 KB 169 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/vi_laval.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/vi_laval.py : connecteur Vï Condos Locatifs (vicondoslocatifs.com,91#   Danam Lacourse) — condos locatifs tout inclus de la Rive-Nord : Terrebonne92#   (225, carré Denise-Pelletier, Urbanova) et Mascouche (1505, place de93#   l'Esplanade). NB : slug historique « vi_laval » de la campagne Laval/94#   Rive-Nord, mais les projets sont à TERREBONNE et MASCOUCHE (Lanaudière).95#   Les pages projet embarquent le widget Planpoint (app.planpoint.io) : on96#   rejoue l'API JSON publique /api/projects/find (voir _planpoint.py).97#   Particularités Vï chez Planpoint : disponibilité en FRANÇAIS98#   (« Disponible ») à Terrebonne, chambres en « 1cc/2cc/3cc » ou99#   « n chambre(s) (+ DEN) », champ type = numéro de modèle.100#   Granularité UNITÉ : prix (Terrebonne), pi², étage, plans par unité.101# -----------------------------------------------------------------------------102from __future__ import annotations103104import re105106from ..schema import Listing107from ._planpoint import planpoint_projects, unit_listing108from .base import BaseConnector109110# (namespace, hostName, url de la page publique, adresse, ville)111PROJECTS = [112    ("vi-condos-locatifs", "vi-condos-locatifs",113     "https://www.vicondoslocatifs.com/vi-terrebonne/",114     "225 carré Denise-Pelletier", "Terrebonne"),115    ("danamlacourse", "Place-de-l-Esplanade",116     "https://www.vicondoslocatifs.com/vi-mascouche/",117     "1505 place de l'Esplanade", "Mascouche"),118]119120_CC_RE = re.compile(r"^\s*(\d+)\s*cc\s*(\+\s*DEN)?\s*$", re.I)121122123class ViLavalConnector(BaseConnector):124    source_id = "vi_laval"125    request_delay = 0.8126127    def fetch(self) -> list[Listing]:128        listings: list[Listing] = []129        for namespace, host, page_url, address, city in PROJECTS:130            try:131                projects = planpoint_projects(self, "projects", namespace, host)132            except Exception:133                continue                     # un projet cassé ne bloque pas134            for project in projects:135                # adresse Planpoint incomplète (« Terrebonne »/None) :136                # on impose l'adresse civique publiée sur le site public137                project["address"] = f"{address}, {city}"138                for floor in project.get("floors") or []:139                    for unit in floor.get("units") or []:140                        self._normalize(unit)141                        lst = unit_listing(self.source_id, project, floor,142                                           unit, page_url=page_url,143                                           default_city=city)144                        if lst is not None:145                            lst.city = city146                            listings.append(lst)147        return listings148149    @staticmethod150    def _normalize(unit: dict) -> None:151        """Adapte les champs Vï au patron générique de _planpoint.py."""152        # « Disponible » (fr) -> « Available » ; « Sold » = loué, exclu153        if (unit.get("availability") or "").strip().lower() == "disponible":154            unit["availability"] = "Available"155        # chambres « 1cc/2cc/3cc » -> « n chambres » (normalize_unit_type156        # sait ensuite dériver 3½/4½/5½)157        beds = str(unit.get("bedrooms") or "").strip()158        m = _CC_RE.match(beds)159        if m:160            n = int(m.group(1))161            unit["bedrooms"] = (f"{n} chambre" + ("s" if n > 1 else "")162                                + (" + DEN" if m.group(2) else ""))163        # le champ type est un numéro de modèle (« 38 ») : déplacé pour que164        # unit_listing dérive le type d'unité des chambres, pas du modèle165        model = str(unit.get("type") or "").strip()166        if model and not re.search(r"[½/]", model):167            unit["type"] = ""168            unit.setdefault("_model", model)169
Files main
Menu

Theme