Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/linea.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/linea.py : connecteur LINÉA (linea.ca) — Trois-Rivières91# Complexe locatif neuf du District 55 (6900, boulevard des Athlètes, secteur92# Trois-Rivières-Ouest), 3 phases. WordPress/WPBakery rendu serveur : chaque93# page /unites/phase-N/ présente les typologies disponibles sous forme de94# colonnes « <type> » (Loft, 3 ½, 4 ½, 5 ½) suivies d'un bloc texte95# « De 1 008 pi² à 1 071 pi² / À partir de 1 750 $ / mois ». Granularité =96# typologie par phase (le site ne publie pas d'inventaire unité par unité).97# external_id = phaseN-<type> — stable tant que la typologie est offerte.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type106107BASE = "https://linea.ca"108PHASES = ("phase-1", "phase-2", "phase-3")109110ADDRESS = "6900, boulevard des Athlètes, Trois-Rivières"111112UNIT_RE = re.compile(r"^\s*(Loft|Studio|\d\s*½)\s*$")113PRICE_RE = re.compile(r"À\s+partir\s+de\s+([\d\s ]+)\s*\$\s*/\s*mois", re.I)114AREA_RE = re.compile(r"(?:De\s+)?([\d\s ]+)\s*pi²(?:\s+à\s+([\d\s ]+)\s*pi²)?",115 re.I)116IMG_RE = re.compile( # /wp-content/uploads/ ou /dist/uploads/ (RocketCDN)117 r"https?://[\w./-]+/uploads/[^\"'\s)\\]+?\.(?:jpg|jpeg|png|webp)", re.I)118IMG_SKIP_RE = re.compile(r"favicon|logo|icon|texture|-\d+x\d+\.", re.I)119120from .base import BaseConnector # noqa: E402 (après les constantes, style maison)121122123def _num(txt: str) -> float | None:124 n = re.sub(r"[\s ]", "", txt or "")125 try:126 return float(n)127 except ValueError:128 return None129130131class LineaConnector(BaseConnector):132 source_id = "linea"133 request_delay = 0.8134135 def fetch(self) -> list[Listing]:136 listings: list[Listing] = []137 for phase in PHASES:138 url = f"{BASE}/unites/{phase}/"139 try:140 html = self.get(url).text141 except Exception:142 continue143 listings.extend(self._parse_phase(phase, url, html))144 return listings145146 def _parse_phase(self, phase: str, url: str, html: str) -> list[Listing]:147 soup = BeautifulSoup(html, "html.parser")148 phase_label = phase.replace("phase-", "Phase ")149150 # Photos de la page (les typologies n'ont pas de galerie propre)151 images = [u for u in dict.fromkeys(IMG_RE.findall(html))152 if not IMG_SKIP_RE.search(u)][:15]153154 listings: list[Listing] = []155 current_type = ""156 # Parcours en ordre du document : un <p> « 4 ½ » annonce la typologie,157 # le <p> suivant porte superficie + « À partir de … $ / mois ».158 for p in soup.select(".wpb_text_column p"):159 text = re.sub(r"\s+", " ", p.get_text(" ", strip=True))160 if not text:161 continue162 m = UNIT_RE.match(text)163 if m:164 current_type = normalize_unit_type(m.group(1))165 continue166 if not current_type:167 continue168 pm = PRICE_RE.search(text)169 if not pm:170 continue171 price = _num(pm.group(1))172 area = None173 desc_bits = [f"{phase_label} du LINÉA (District 55)"]174 am = AREA_RE.search(text)175 if am:176 area = _num(am.group(1))177 if am.group(2):178 desc_bits.append(f"Superficies de {am.group(1).strip()} à "179 f"{am.group(2).strip()} pi²")180 ext_id = f"{phase}-{current_type.replace('½', '.5').lower()}"181 ext_id = re.sub(r"[^\w.\-]", "-", ext_id)182 listings.append(Listing(183 source=self.source_id,184 external_id=ext_id,185 url=url,186 title=f"{current_type} — LINÉA {phase_label}",187 address=ADDRESS,188 sector="Trois-Rivières-Ouest",189 city="Trois-Rivières",190 unit_type=current_type,191 price=price,192 price_label=pm.group(0),193 area_sqft=area,194 description=" | ".join(desc_bits),195 images=images,196 ))197 current_type = ""198 return listings199