Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/primo.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/primo.py : connecteur Primo Immobilier (primoimmobilier.ca —91# condos locatifs de luxe en Montérégie : Lumicité Condominiums à92# Saint-Mathieu-de-Beloeil et Quartier Trinité à Saint-Basile-le-Grand).93# WordPress rendu serveur mais SANS inventaire d'unités : chaque page94# projet affiche un seul prix plancher « À partir de 2075$/mois » (les95# typologies 3½/4½/5½ n'apparaissent que dans le formulaire, sans prix).96# Granularité = PROJET (une annonce par projet, prix « à partir de »).97# external_id = slug de la page projet — stable.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import html as _html102import re103104from ..schema import Listing105from .base import BaseConnector106107BASE = "https://primoimmobilier.ca"108109# (slug page, nom du projet, ville)110PROJECTS: tuple[tuple[str, str, str], ...] = (111 ("saint-mathieu-de-beloeil", "Lumicité Condominiums",112 "Saint-Mathieu-de-Beloeil"),113 ("saint-basile-le-grand", "Quartier Trinité", "Saint-Basile-le-Grand"),114)115116H1_RE = re.compile(r"<h1[^>]*>([\s\S]*?)</h1>", re.I)117FROM_RE = re.compile(r"À\s+partir\s+de\s+([\d\s ]{3,9})\$\s*/\s*mois", re.I)118SCRIPT_RE = re.compile(r"<(script|style)[\s\S]*?</\1>", re.I)119TAG_RE = re.compile(r"<[^>]+>")120IMG_RE = re.compile(121 r'https://primoimmobilier\.ca/wp-content/[^"\s)]+\.(?:jpe?g|png|webp)',122 re.I)123124125class PrimoConnector(BaseConnector):126 source_id = "primo"127 request_delay = 0.8128129 def fetch(self) -> list[Listing]:130 listings: list[Listing] = []131 for slug, name, city in PROJECTS:132 url = f"{BASE}/{slug}/"133 try:134 html = self.get(url).text135 except Exception:136 continue137 flat = re.sub(r"[\s ]+", " ",138 TAG_RE.sub(" ", _html.unescape(139 SCRIPT_RE.sub(" ", html))))140 pm = FROM_RE.search(flat)141 price = None142 if pm:143 try:144 price = float(re.sub(r"[\s ]", "", pm.group(1)))145 except ValueError:146 price = None147 if price is None or not (500 <= price <= 8000):148 continue # pas de prix publié = pas d'annonce149150 hm = H1_RE.search(html)151 title = (re.sub(r"\s+", " ", _html.unescape(152 TAG_RE.sub(" ", hm.group(1)))).strip()153 if hm else f"Condos locatifs {name}")154155 images = [u for u in dict.fromkeys(IMG_RE.findall(html))156 if not re.search(r"logo|icon|favicon|banners", u, re.I)157 ][:10]158159 listings.append(Listing(160 source=self.source_id,161 external_id=slug,162 url=url,163 title=title,164 address="", # adresse civique non publiée165 city=city,166 price=price,167 price_label=f"à partir de {int(price)} $/mois",168 description=f"{name} à {city} — condos locatifs de luxe de "169 "Primo Immobilier (typologies 3½ à 5½). "170 "Ascenseur, stationnement et rangement "171 "intérieurs, plafonds de 9 pieds, comptoirs de "172 "quartz, accessible aux personnes à mobilité "173 "réduite.",174 images=images,175 ))176 return listings177