Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/uneo.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/uneo.py : connecteur Unéo Gestion Immobilière (uneo.ca)91# Acquisition-construction-gestion en Montérégie : Saint-Jean-sur-Richelieu,92# Saint-Hyacinthe, Otterburn Park. WordPress (thème immobilier) rendu93# serveur : /projets liste les fiches, chaque fiche /projets/<slug>/ donne94# des faits structurés (« Emplacement », « Type d'unité », « Superficie »,95# « Nombre d'unités », « À partir de X$/mois »).96# Granularité : une annonce par projet × typologie, prix « à partir de »97# du projet (borne basse commune à ses typologies).98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102103from bs4 import BeautifulSoup104105from ..schema import Listing, normalize_unit_type, parse_price106from .base import BaseConnector107108BASE = "https://uneo.ca"109LIST_URL = f"{BASE}/projets"110111PROJECT_LINK_RE = re.compile(r"https://uneo\.ca/projets/([\w\-]+)/?")112UNIT_TOKEN_RE = re.compile(r"\b(\d)\s*(?:½|1/2)")113# « À partir de 1550$/mois » (l'espace ou le retour à la ligne varie)114PRICE_RE = re.compile(r"[ÀA]\s*partir\s+de\s*:?\s*([\d\s,]{3,9})\s*\$\s*/?\s*mois", re.I)115AREA_RE = re.compile(r"([\d\s]{3,6}(?:\s*[àa@\-]\s*[\d\s]{3,6})?)\s*pieds?\s+carr[ée]s?", re.I)116UNITS_COUNT_RE = re.compile(r"Nombre d[’']unit[ée]s\s*:?\s*(\d{1,4})", re.I)117IMG_RE = re.compile(118 r"https://uneo\.ca/wp-content/uploads/"119 r'[^"\s\\)]+\.(?:jpe?g|png|webp|avif)', re.I)120121122class UneoConnector(BaseConnector):123 source_id = "uneo"124 request_delay = 0.8125 max_projects = 15 # garde-fou de crawl126127 def fetch(self) -> list[Listing]:128 listings: list[Listing] = []129 try:130 html = self.get(LIST_URL).text131 except Exception:132 return listings133134 slugs = [s for s in dict.fromkeys(PROJECT_LINK_RE.findall(html))135 if s not in ("feed",)]136 for slug in slugs[: self.max_projects]:137 try:138 listings.extend(self._fetch_project(slug))139 except Exception:140 continue141 return listings142143 def _fetch_project(self, slug: str) -> list[Listing]:144 url = f"{BASE}/projets/{slug}/"145 html = self.get(url).text146 soup = BeautifulSoup(html, "html.parser")147 for tag in soup(["script", "style", "noscript"]):148 tag.decompose()149150 h1 = soup.find("h1")151 name = h1.get_text(" ", strip=True) if h1 else \152 slug.replace("-", " ").title()153 text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))154155 # faits structurés de la fiche156 m = re.search(r"Emplacement\s*:?\s*([A-ZÉÈ][\w\- ]{3,40}?)"157 r"(?:\s+(?:Nombre|Superficie|Type|Année|À partir)|$)", text)158 city = m.group(1).strip() if m else "Saint-Jean-sur-Richelieu"159160 m = re.search(r"Type d[’']unit[ée]s?\s*:?\s*([\d\s½,/et]+)", text)161 unit_zone = m.group(1) if m else ""162 unit_types = list(dict.fromkeys(163 normalize_unit_type(f"{n}½")164 for n in UNIT_TOKEN_RE.findall(unit_zone)))165 if not unit_types:166 unit_types = [""]167168 price_label = ""169 m = PRICE_RE.search(text)170 if m:171 price_label = f"À partir de {m.group(1).strip()}$/mois"172173 area_label = ""174 m = AREA_RE.search(text)175 if m:176 area_label = m.group(0).strip()177178 n_units = None179 m = UNITS_COUNT_RE.search(text)180 if m:181 n_units = int(m.group(1))182183 # description : paragraphe de présentation184 description = ""185 for p in soup.find_all("p"):186 pt = p.get_text(" ", strip=True)187 if len(pt) > 120 and "consentement" not in pt.lower() \188 and "cookies" not in pt.lower():189 description = pt[:900]190 break191192 # adresse civique éventuelle dans la prose (« au 632 rue Champlain »)193 address = ""194 m = re.search(r"(?:au|le)\s+(\d{1,5}[,]?\s+(?:rue|avenue|boulevard|"195 r"chemin|route)\s+[\w\-' ]{2,40})", text, re.I)196 if m:197 address = m.group(1).strip()198199 amenities: list[str] = []200 for kw, label in [201 (r"ascenseur", "Ascenseur"),202 (r"garage souterrain|stationnement au garage", "Garage/stationnement intérieur"),203 (r"internet (?:haute vitesse )?inclus", "Internet inclus"),204 (r"balayeuse centrale", "Balayeuse centrale"),205 (r"interphone|intercom", "Interphone"),206 (r"borne [ée]lectrique", "Borne électrique ($)"),207 (r"remise int[ée]rieure", "Remise intérieure"),208 (r"balcon", "Balcon"),209 (r"thermopompe", "Thermopompe"),210 (r"animaux accept[ée]s|animaux de compagnie sont bienvenus",211 "Animaux acceptés (conditions)"),212 ]:213 if re.search(kw, text, re.I):214 amenities.append(label)215 if area_label:216 amenities.append(f"Superficie : {area_label}")217218 details: dict = {}219 if n_units:220 details["building_units"] = n_units221222 images = [u for u in dict.fromkeys(IMG_RE.findall(html))223 if not re.search(r"logo|icon|favicon|cropped-|plan|"224 r"-\d{2,3}x\d{2,3}\.", u, re.I)][:20]225226 out: list[Listing] = []227 for ut in unit_types:228 ext = f"{slug}-{ut.replace('½', '.5')}" if ut else slug229 out.append(Listing(230 source=self.source_id,231 external_id=ext,232 url=url,233 title=f"{name} — {ut}" if ut else name,234 address=address,235 city=city,236 unit_type=ut,237 price=parse_price(price_label),238 price_label=price_label,239 description=description,240 amenities=list(dict.fromkeys(amenities)),241 details=dict(details),242 images=images,243 ))244 return out245