SPB Git

Repository Public

sovima.py 8.2 KB 207 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/sovima.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/sovima.py : connecteur Groupe Sovima (groupesovima.com)91#   Appartements/condos locatifs neufs de la Rive-Sud (+ Repentigny) :92#   AlterEGO (Brossard), Le Nest (Saint-Bruno-de-Montarville), Quartier93#   Vauquelin 2 (Longueuil) et Le Neuf Cent Notre-Dame (Repentigny).94#   Nest Ottawa (Ontario) exclu. Site Webflow rendu serveur : chaque projet a95#   une page /nos-plans avec les typologies et le prix plancher — motif texte96#   « <n> ½ … À PARTIR DE <prix> $ / mois » (ou « Non disponible pour le97#   moment », ignoré). Granularité = TYPOLOGIE par projet.98#   external_id = <projet>-<n>-demi — stable. ⚠️ Webflow sans charset dans les99#   en-têtes -> forcer UTF-8 (même piège que aera3r).100# -----------------------------------------------------------------------------101from __future__ import annotations102103import html as _html104import re105106from ..schema import Listing107from .base import BaseConnector108109BASE = "https://www.groupesovima.com"110111# (slug projet, nom, adresse, ville)112SITES: tuple[tuple[str, str, str, str], ...] = (113    ("alterego", "AlterEGO sur le fleuve",114     "Tour 2, 8355, boulevard du St-Laurent, Brossard", "Brossard"),115    ("le-nest", "Le Nest",116     "2000, rue Benoît, Saint-Bruno-de-Montarville",117     "Saint-Bruno-de-Montarville"),118    ("quartier-vauquelin", "Quartier Vauquelin 2",119     "4325, rue des Dirigeables, Longueuil", "Longueuil"),120    ("le-neuf-cent", "Le Neuf Cent Notre-Dame",121     "900, rue Notre-Dame, Repentigny", "Repentigny"),122)123124# « 3 ½ À PARTIR DE 1770 $ / mois » dans le texte aplati (tags -> espaces)125PLAN_RE = re.compile(126    r"(\d)\s*½\s*À\s+PARTIR\s+DE\s+([\d\s  ,]{3,9})\$\s*/\s*mois", re.I)127SCRIPT_RE = re.compile(r"<(script|style)[\s\S]*?</\1>", re.I)128TAG_RE = re.compile(r"<[^>]+>")129IMG_RE = re.compile(130    r'(?:src|href)="(https://cdn\.prod\.website-files\.com/[^"\s]+'131    r"\.(?:jpe?g|png|webp|avif))", re.I)132133134def _num(txt: str) -> float | None:135    n = re.sub(r"[\s  ,]", "", txt or "")136    try:137        return float(n)138    except ValueError:139        return None140141142class SovimaConnector(BaseConnector):143    source_id = "sovima"144    request_delay = 0.8145146    def fetch(self) -> list[Listing]:147        listings: list[Listing] = []148        for slug, name, address, city in SITES:149            url = f"{BASE}/{slug}/nos-plans"150            try:151                resp = self.get(url)152                resp.encoding = "utf-8"      # Webflow sans charset -> latin-1153                html = resp.text154            except Exception:155                continue156            # photos : la page /nos-plans n'a pas de galerie, on prend celle157            # de /nos-appartements (rendue serveur elle aussi)158            photos_html = ""159            try:160                p = self.get(f"{BASE}/{slug}/nos-appartements")161                p.encoding = "utf-8"162                photos_html = p.text163            except Exception:164                pass165            listings.extend(self._parse(slug, url, name, address, city,166                                        html, photos_html))167        return listings168169    def _parse(self, slug: str, url: str, name: str, address: str,170               city: str, html: str, photos_html: str = "") -> list[Listing]:171        text = _html.unescape(SCRIPT_RE.sub(" ", html))172        flat = re.sub(r"[\s  ]+", " ", TAG_RE.sub(" ", text))173174        images = [u for u in dict.fromkeys(175                      IMG_RE.findall(html) + IMG_RE.findall(photos_html))176                  if not re.search(r"logo|favicon|webclip|icon|opengraph",177                                   u, re.I)][:8]178179        listings: list[Listing] = []180        seen: set[str] = set()181        for m in PLAN_RE.finditer(flat):182            n = int(m.group(1))183            price = _num(m.group(2))184            if not (2 <= n <= 7) or price is None or not (500 <= price <= 8000):185                continue186            ext_id = f"{slug}-{n}-demi"187            if ext_id in seen:               # motif répété dans la page188                continue189            seen.add(ext_id)190            unit_type = f"{n}½"191            listings.append(Listing(192                source=self.source_id,193                external_id=ext_id,194                url=url,195                title=f"{unit_type} — {name}",196                address=address,197                sector="",198                city=city,199                unit_type=unit_type,200                price=price,201                price_label=f"à partir de {int(price)} $ / mois",202                description=f"{unit_type} au {name} ({address}) — projet "203                            "locatif du Groupe Sovima.",204                images=list(images),205            ))206        return listings207
Files main
Menu

Theme