SPB Git

Repository Public

station_horizon.py 7.8 KB 195 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/station_horizon.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/station_horizon.py : connecteur Station Horizon91#   (stationhorizon.com) — condos locatifs neufs au 550-650-700, boulevard92#   de la Gare, Mont-Saint-Hilaire (Village de la Gare), 2 phases. WordPress93#   rendu serveur : les pages « Plans des unités » (phase 1 et 2) exposent94#   les plans par typologie dans les noms de fichiers webp95#   (« …Phase-1-3.1-2_TypeC.webp » = 3½ type C). Les prix ne sont pas dans96#   les pages de plans : ils viennent de l'accueil (« À partir de : 3 ½97#   1 775$ / mois | 4 ½ 2 600$ | 5 ½ 2 625$ », tout inclus). Une annonce par98#   phase × typologie (pas d'inventaire unité par unité public), avec les99#   plans de la typologie en images.100# -----------------------------------------------------------------------------101from __future__ import annotations102103import re104105from bs4 import BeautifulSoup106107from ..schema import Listing108from .base import BaseConnector109110BASE = "https://stationhorizon.com"111HOME_URL = f"{BASE}/"112PHASES = {113    1: f"{BASE}/plans-des-unites-phase-1/",114    2: f"{BASE}/plans-des-unites-phase-2/",115}116117ADDRESS = "550-650-700, boulevard de la Gare, Mont-Saint-Hilaire"118CITY = "Mont-Saint-Hilaire"119PHONE = "514-900-3339"120121# prix plancher par typologie sur l'accueil : « 3 ½ 1 775$ / mois »122PRICE_RE = re.compile(r"(\d)\s*½\s*([\d\s  ]{3,8})\$\s*/\s*mois")123# plan d'unité : « …Phase-1-3.1-2_TypeC.webp », « …Phase-2-4.1-2_Type-15.webp »124PLAN_RE = re.compile(125    r"https://(?:www\.)?stationhorizon\.com/wp-content/uploads/"126    r"[^\"\s\\']*Phase-(\d)-(\d)\.1-2_Type-?([\w]+?)(?:-scaled)?"127    r"\.(?:webp|png|jpe?g)", re.I)128# inclusions : segment « Ce qui est inclus … Écrivez-nous » de l'accueil129INCLUS_RE = re.compile(r"Ce qui est inclus(.{10,500}?)(?:Écrivez-nous|$)")130131132class StationHorizonConnector(BaseConnector):133    source_id = "station_horizon"134    request_delay = 0.6135136    def fetch(self) -> list[Listing]:137        listings: list[Listing] = []138139        # accueil : prix par typologie + inclusions140        prices: dict[str, tuple[float, str]] = {}141        amenities: list[str] = []142        try:143            home = self.get(HOME_URL).text144            text = re.sub(r"\s+", " ",145                          BeautifulSoup(home, "html.parser")146                          .get_text(" ", strip=True))147            for m in PRICE_RE.finditer(text):148                try:149                    val = float(re.sub(r"[^\d]", "", m.group(2)))150                except ValueError:151                    continue152                label = re.sub(r"[  ]", " ", m.group(2)).strip()153                prices[f"{m.group(1)}½"] = \154                    (val, f"À partir de {label}$ / mois")155            m = INCLUS_RE.search(text)156            if m:157                amenities = [a.strip() for a in re.split(158                    r"(?<=[a-zé)])\s+(?=[A-ZÉ5])", m.group(1).strip())159                    if len(a.strip()) > 2][:10]160        except Exception:161            pass162163        # pages de plans : typologies offertes par phase164        for phase, url in PHASES.items():165            try:166                html = self.get(url).text167            except Exception:168                continue169            plans: dict[str, list[str]] = {}170            for m in PLAN_RE.finditer(html):171                if int(m.group(1)) != phase:172                    continue173                unit_type = f"{m.group(2)}½"174                if m.group(0) not in plans.setdefault(unit_type, []):175                    plans[unit_type].append(m.group(0))176            for unit_type, imgs in sorted(plans.items()):177                price, price_label = prices.get(unit_type, (None, ""))178                listings.append(Listing(179                    source=self.source_id,180                    external_id=f"phase{phase}-"181                                f"{unit_type.replace('½', '.5')}",182                    url=url,183                    title=f"{unit_type} — Station Horizon, phase {phase}",184                    address=ADDRESS,185                    city=CITY,186                    unit_type=unit_type,187                    price=price,188                    price_label=price_label,189                    amenities=list(amenities),190                    details={"contact": {"phone": PHONE},191                             "nb_plans": len(imgs)},192                    images=imgs[:12],193                ))194        return listings195
Files main
Menu

Theme