SPB Git

Repository Public

vallensis.py 6.5 KB 166 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/vallensis.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/vallensis.py : connecteur Vallensis (vallensis.ca)91#   Condos locatifs neufs à Salaberry-de-Valleyfield (503, rue92#   Jacques-Cartier) — bâtiments de 20 unités (647 à 1148 pi²).93#   WordPress/Elementor rendu serveur : la page d'accueil affiche une carte94#   par typologie (« 3 ½ / À partir de / 1550$/mois »). Granularité :95#   typologie (pas d'unités individuelles publiées).96# -----------------------------------------------------------------------------97from __future__ import annotations9899import re100101from bs4 import BeautifulSoup102103from .base import BaseConnector104from ..schema import Listing105106BASE = "https://vallensis.ca"107108ADDRESS = "503, rue Jacques-Cartier, Salaberry-de-Valleyfield"109CITY = "Salaberry-de-Valleyfield"110111TYPE_RE = re.compile(r"^\d\s*½$")112PRICE_RE = re.compile(r"(\d[\d\s  ]{2,6})\$\s*/\s*mois", re.I)113IMG_RE = re.compile(r'https://vallensis\.ca/wp-content/uploads/'114                    r'[^"\s\\)]+\.(?:jpe?g|png|webp)', re.I)115116117class VallensisConnector(BaseConnector):118    source_id = "vallensis"119    request_delay = 0.6120121    def fetch(self) -> list[Listing]:122        listings: list[Listing] = []123        try:124            html = self.get(BASE + "/").text125        except Exception:126            return listings127        soup = BeautifulSoup(html, "html.parser")128        lines = soup.get_text("\n", strip=True).split("\n")129130        images = [u for u in dict.fromkeys(IMG_RE.findall(html))131                  if not re.search(r"logo|icon|favicon|plan|"132                                   r"-\d{2,3}x\d{2,3}\.", u, re.I)][:15]133134        # cartes « 3 ½ / À partir de / 1550$/mois » (dans l'ordre du texte)135        for i, line in enumerate(lines):136            if not TYPE_RE.match(line.strip()):137                continue138            window = " ".join(lines[i + 1:i + 4])139            m = PRICE_RE.search(window)140            if not m:141                continue142            unit_type = line.strip().replace(" ", "")143            try:144                price = float(m.group(1).replace(" ", "").replace(" ", ""))145            except ValueError:146                continue147            ext_id = f"valleyfield-{unit_type.replace('½', '.5')}"148            if any(l.external_id == ext_id for l in listings):149                continue150            listings.append(Listing(151                source=self.source_id,152                external_id=ext_id,153                url=BASE + "/",154                title=f"{unit_type} — Vallensis",155                address=ADDRESS,156                city=CITY,157                unit_type=unit_type,158                price=price,159                price_label=f"À partir de {m.group(0)}",160                description="Condos locatifs neufs réalisés par le Groupe "161                            "Architecte PDA — bâtiments de 20 unités de 647 "162                            "à 1148 pi², esprit épuré et moderne.",163                images=images,164            ))165        return listings166
Files main
Menu

Theme