SPB Git

Repository Public

vita_stl.py 7.1 KB 185 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/vita_stl.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/vita_stl.py : connecteur Appartements VITA (appartementsvita.ca)91#   2505, boulevard Marcel-Laurin, Saint-Laurent (Montréal) — deux phases,92#   1½ à 5½, à deux pas du REM Bois-Franc. WordPress/Elementor : le sélecteur93#   d'unités (plugin wp-floor-plans) ne retourne AUCUNE unité individuelle94#   (vérifié via admin-ajax sur les deux phases et tous les étages) — la page95#   d'accueil affiche plutôt une ligne par type : « 3 ½ à partir de 1650$ »96#   ou « 1 ½ : liste d'attente ». Une annonce par type avec prix réel (les97#   types en liste d'attente sont exclus), id stable vita-<type>.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing106from .base import BaseConnector107108BASE = "https://appartementsvita.ca"109ADDRESS = "2505, boulevard Marcel-Laurin, Saint-Laurent, Montréal, QC H4R 0R7"110111_TYPE_RE = re.compile(r"^([1-6])\s*½\s*(.*)$")112_PRICE_RE = re.compile(r"à partir de\s*([\d\s,]+)\s*\$", re.I)113_IMG_RE = re.compile(114    r'https://appartementsvita\.ca/wp-content/uploads/[^"\'\s\\)]+?'115    r'\.(?:jpg|jpeg|png|webp)', re.I)116_SKIP_IMG = re.compile(r"logo|icon|favicon|-\d{2,4}x\d{2,4}\.", re.I)117118119class VitaStlConnector(BaseConnector):120    source_id = "vita_stl"121    request_delay = 0.6122    max_images = 20123124    def fetch(self) -> list[Listing]:125        html = self.get(f"{BASE}/").text126        soup = BeautifulSoup(html, "html.parser")127128        # galerie du projet (accueil, sans logos/miniatures)129        images: list[str] = []130        for u in _IMG_RE.findall(html):131            if _SKIP_IMG.search(u):132                continue133            if u not in images:134                images.append(u)135        images = images[: self.max_images]136137        # description : méta de la page138        desc = ""139        meta = soup.find("meta", attrs={"name": "description"})140        if meta and meta.get("content"):141            desc = meta["content"].strip()[:600]142        if not desc:143            og = soup.find("meta", property="og:description")144            if og and og.get("content"):145                desc = og["content"].strip()[:600]146147        # une ligne « n ½ … » par type dans les listes à icônes Elementor148        listings: list[Listing] = []149        seen: set[str] = set()150        for span in soup.select(".elementor-icon-list-text"):151            t = span.get_text(" ", strip=True)152            m = _TYPE_RE.match(t)153            if not m:154                continue155            n, rest = m.group(1), m.group(2)156            unit_type = f"{n}½"157            if unit_type in seen:158                continue159            pm = _PRICE_RE.search(rest)160            if not pm:161                continue             # « liste d'attente » : exclu162            digits = re.sub(r"[^\d]", "", pm.group(1))163            if not digits:164                continue165            price = float(digits)166            if not (100 <= price <= 20000):167                continue168            seen.add(unit_type)169            listings.append(Listing(170                source=self.source_id,171                external_id=f"vita-{n}5",172                url=f"{BASE}/",173                title=f"Appartements VITA — {unit_type}",174                address=ADDRESS,175                sector="Saint-Laurent",176                city="Montréal",177                unit_type=unit_type,178                price=price,179                price_label=f"À partir de {int(price)} $/mois",180                availability=t,181                description=desc,182                images=list(images),183            ))184        return listings185
Files main
Menu

Theme