Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/in_via.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/in_via.py : connecteur IN VIA appartements urbains91# (inviamirabel.com — CAP Immobilier, appartements locatifs neufs au92# 14385 et 14365 rue Roger-Thomas, secteur Saint-Janvier à Mirabel,93# phases de 32 unités). WordPress/Elementor rendu SERVEUR : la page94# /appartements/ annonce les typologies offertes en location (3½, 4½,95# 5½) et les phases avec leur adresse ; AUCUN prix ni disponibilité par96# unité publiés (« renseignez-vous sur la disponibilité ») — rien97# d'inventé. Granularité TYPOLOGIE (external_id = « invia-N.5 », stable).98# Les phases « À venir » ne créent pas d'annonce distincte.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing, normalize_unit_type107from .base import BaseConnector108109BASE = "https://www.inviamirabel.com"110PAGE_URL = f"{BASE}/appartements/"111ADDRESS = "14385, rue Roger-Thomas"112SECTOR = "Saint-Janvier"113CITY = "Mirabel"114115# « Louez un appartement 3 ½, 4 ½ ou 5 ½ »116OFFER_RE = re.compile(r"Louez un appartement((?:\s*\d\s*½[,\s]*(?:ou)?\s*)+)",117 re.I)118TYPO_RE = re.compile(r"(\d)\s*½")119PHASE_RE = re.compile(r"Phase\s*(\d+)\s+((?:\d{4,5}\s+)?[\wÀ-ü' -]+?)"120 r"(?=\s*(?:Plans intérieurs|Phase|$))")121IMG_RE = re.compile(r"https://www\.inviamirabel\.com/wp-content/uploads/"122 r"[^\"\s\\]+?\.(?:jpe?g|png|webp)", re.I)123IMG_SIZE_RE = re.compile(r"-\d+x\d+(?=\.(?:jpe?g|png|webp))", re.I)124125126class InViaConnector(BaseConnector):127 source_id = "in_via"128 request_delay = 0.8129130 def fetch(self) -> list[Listing]:131 try:132 html = self.get(PAGE_URL).text133 except Exception:134 return []135 soup = BeautifulSoup(html, "html.parser")136 text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))137138 # typologies réellement offertes (« Louez un appartement 3 ½, 4 ½ ou 5 ½ »)139 m = OFFER_RE.search(text)140 typos = TYPO_RE.findall(m.group(1)) if m else TYPO_RE.findall(text[:600])141 typos = list(dict.fromkeys(typos))142 if not typos:143 return []144145 # phases livrées (adresse civique) — « Phase 3 À venir » ignorée146 phases: list[str] = []147 for pm in PHASE_RE.finditer(text):148 label = pm.group(2).strip()149 if re.match(r"^\d{4,5}\s", label):150 phases.append(f"Phase {pm.group(1)} : {label}")151152 # description : paragraphes de présentation du site153 desc_parts: list[str] = []154 for pat in (r"(Déménagez dans un appartement[^.]+\.)",155 r"(Vivez dans un espace de vie neuf[^.]+\.)",156 r"(Chaque unité inclut un stationnement[^.]+\.)"):157 mm = re.search(pat, text)158 if mm:159 desc_parts.append(mm.group(1).strip())160 blurb = " ".join(desc_parts)161162 images = []163 for u in dict.fromkeys(IMG_RE.findall(html)):164 u = IMG_SIZE_RE.sub("", u)165 if not re.search(r"logo|icon|favicon|plan", u, re.I) \166 and u not in images:167 images.append(u)168169 amenities = ["Comptoirs de quartz", "Air climatisé",170 "Stationnement intérieur inclus",171 "Espace de rangement au garage"]172 listings: list[Listing] = []173 for t in typos:174 unit_type = normalize_unit_type(f"{t} 1/2")175 listings.append(Listing(176 source=self.source_id,177 external_id=f"invia-{t}.5",178 url=PAGE_URL,179 title=f"Appartement {unit_type} — IN VIA Mirabel",180 address=ADDRESS,181 sector=SECTOR,182 city=CITY,183 unit_type=unit_type,184 description=(blurb + (" " + " | ".join(phases)185 if phases else ""))[:1200],186 amenities=amenities,187 details={"phases": phases} if phases else {},188 images=images[:20],189 ))190 return listings191