SPB Git

Repository Public

mellem.py 6.8 KB 165 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/mellem.py10# Module           : louka11# Repository       : https://git.spboucher.ai/lou-ka12# Created          : 2026-08-0913# Last Modified    : 2026-10-2214#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/mellem.py : connecteur Mellem (mellem.ca — Groupe Mach)91#   Projets locatifs Mellem : Manoir-des-Trembles (Gatineau), Grace Dart et92#   Ville-Marie (Montréal). Inventaire servi par Livya (app.livya.com,93#   client « maitre-carre ») : voir _livya.py (flux RSC des pages inventory94#   du client depuis la refonte Livya du 2026-10-22 — avant : modules95#   « plans » embarqués dans les pages /projets/<slug> de mellem.ca, dont le96#   flux RSC n'embarque plus les unités).97#   ⚠️ L'inventaire « Maitre-Carré » couvre TOUT le portefeuille du98#   gestionnaire : on ne garde que les immeubles des projets publiés sur99#   mellem.ca (sitemap, comme l'ancien connecteur) — Evol a son propre100#   connecteur (evol.py) et Noria n'est pas une marque Mellem.101#   external_id historique conservé : {slug mellem.ca}-{numéro d'unité}102#   (ex. grace-dart-121) — zéro churn à travers la migration.103# -----------------------------------------------------------------------------104from __future__ import annotations105106import re107108from ..schema import Listing109from ._livya import LivyaConnector110111BASE = "https://www.mellem.ca"112SITEMAP_URL = f"{BASE}/sitemap.xml"113114115class MellemConnector(LivyaConnector):116    source_id = "mellem"117    client = "maitre-carre"118    brand = "Mellem"119    site_url = BASE120    default_city = "Montréal"121    # repli selectorId si la découverte casse (sélecteur « Maitre-Carré »122    # résidentiel, relevé 2026-10-22)123    default_inventory = ["63858055-ff37-47a7-b785-3e75b140532a"]124    # repli si le sitemap de mellem.ca casse (slugs /projets/ relevés125    # 2026-10-22)126    fallback_slugs = ["grace-dart", "manoir-des-trembles", "ville-marie",127                      "candiac"]128129    def _project_slugs(self) -> list[str]:130        """Slugs des projets Mellem, depuis le sitemap de mellem.ca."""131        try:132            xml = self.get(SITEMAP_URL).text133            urls = re.findall(r"<loc>\s*([^<\s]+)\s*</loc>", xml)134            slugs = [m.group(1) for u in dict.fromkeys(urls)135                     if (m := re.match(136                         rf"^{re.escape(BASE)}/projets/([^/]+)/?$", u))]137        except Exception:138            slugs = []139        return slugs or list(self.fallback_slugs)140141    def fetch(self) -> list[Listing]:142        self._slugs = self._project_slugs()143        # _listing retourne None pour les immeubles hors Mellem144        return [l for l in super().fetch() if l is not None]145146    def _mellem_slug(self, building_slug: str) -> str | None:147        """Slug mellem.ca correspondant à un immeuble Livya (les immeubles148        Grace Dart - B/C portent les slugs grace-dart-b/grace-dart-c)."""149        for s in self._slugs:150            if building_slug == s or building_slug.startswith(f"{s}-"):151                return s152        return None153154    def _listing(self, u: dict, sel: str,155                 buildings: dict[str, tuple[str, str]]) -> Listing | None:156        bslug = buildings.get(u.get("buildingId") or "", ("", ""))[1]157        slug = self._mellem_slug(bslug)158        if slug is None:159            return None            # Evol, Noria… : hors marque Mellem160        lst = super()._listing(u, sel, buildings)161        num = str(u.get("number") or "").strip()162        lst.external_id = f"{slug}-{num}"163        lst.url = f"{BASE}/projets/{slug}#unite-{num}"164        return lst165
Files main
Menu

Theme