SPB Git

Repository Public

beloeil_94.py 6.9 KB 180 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/beloeil_94.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/beloeil_94.py : connecteur Le 94 Vieux-Beloeil (94beloeil.ca)91#   Immeuble unique au 915, rue Guertin (Vieux-Beloeil) : commerce au RDC et92#   8 appartements 3½ (1 c.c.) au-dessus. Site vitrine statique (constructeur93#   maison, rendu serveur) : une seule offre affichée sous forme de bandeau94#   « 3 1/2 disponible <mois année> » + liste des inclusions. Granularité :95#   typologie (une annonce 3½ quand l'immeuble affiche une disponibilité).96# -----------------------------------------------------------------------------97from __future__ import annotations9899import re100101from bs4 import BeautifulSoup102103from .base import BaseConnector104from ..schema import Listing105106BASE = "https://www.94beloeil.ca"107108ADDRESS = "915, rue Guertin, Beloeil"109110# « 3 1/2 disponible Août 2026 » (bandeau d'accueil)111AVAIL_RE = re.compile(r"(\d\s*(?:1/2|½))\s*disponibles?\s*([\w'’éûà]+\s*\d{4}|"112                      r"maintenant|imm[ée]diatement)", re.I)113SQFT_RE = re.compile(r"(\d{3,4})\s*(?:à\s*(\d{3,4})\s*)?pieds?\s*carr[ée]s", re.I)114IMG_RE = re.compile(r'(?:src|href)="(/uploads/[^"]+\.(?:jpe?g|png|webp))"', re.I)115116117class Beloeil94Connector(BaseConnector):118    source_id = "beloeil_94"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        text = soup.get_text("\n", strip=True)129130        m = AVAIL_RE.search(text)131        if not m:132            return listings           # rien d'affiché = aucune disponibilité133134        unit_type = m.group(1).replace(" ", " ")135        availability = f"Disponible {m.group(2)}"136137        # superficie « 685 à 747 pieds carrés » (fourchette de l'immeuble)138        sqft = None139        ms = SQFT_RE.search(text)140        if ms:141            try:142                sqft = float(ms.group(1))143            except ValueError:144                sqft = None145146        # inclusions : liste à puces autour de la fiche de l'immeuble147        amenities: list[str] = []148        lines = text.split("\n")149        try:150            start = next(i for i, l in enumerate(lines) if "électro inclus" in l)151            for l in lines[start:start + 25]:152                if 3 < len(l) < 60 and not l.startswith(("Pour ", "Un ")):153                    amenities.append(l)154        except StopIteration:155            pass156157        images = [BASE + u for u in dict.fromkeys(IMG_RE.findall(html))158                  if not re.search(r"logo|icon|-\[converted\]", u, re.I)][:15]159160        listings.append(Listing(161            source=self.source_id,162            external_id="guertin-3.5",163            url=BASE + "/",164            title="3½ — Le 94 Vieux-Beloeil",165            address=ADDRESS,166            sector="Vieux-Beloeil",167            city="Beloeil",168            unit_type="3½",169            bedrooms=1,170            bathrooms=1,171            availability=availability,172            area_sqft=sqft,173            description="Immeuble construit en 2020 avec commerce au RDC et "174                        "8 unités d'une chambre à coucher au-dessus. "175                        "Design moderne et lumineux.",176            amenities=list(dict.fromkeys(amenities))[:15],177            images=images,178        ))179        return listings180
Files main
Menu

Theme