Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/junic.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/junic.py : connecteur Junic (junic.ca — promoteur de Gatineau :91# projets Agora Village Urbain, VILL, Central…)92# Seul l'AGORA publie un inventaire exploitable : la page93# residentiel.agora-plateau.com/appartements/ (WordPress/Jupiter) est rendue94# SERVEUR avec une carte par unité disponible (div.unit) regroupée par95# typologie (h2 : Micro, Loft, 1 chambre, 1 chambre + bureau…) :96# numéro « 20 - #320 » (immeuble 20 ou 35, rue de Hambourg, secteur97# Le Plateau à Gatineau), disponibilité (date ou « MAINTENANT DISPONIBLE »),98# type, dimension pi², LOYER de base, forfait tout-inclus obligatoire99# (505 $/mois : meubles en option non — chauffage/clim, internet…),100# mensualité totale, visite virtuelle et plan de l'unité.101# Le prix publié est le LOYER de base ; le forfait et la mensualité totale102# sont reportés en description/détails. VILL (villappartements.com) n'a103# qu'un portail résident Building Stack avec login — aucune annonce104# publique, donc hors connecteur.105# -----------------------------------------------------------------------------106from __future__ import annotations107108import re109110from bs4 import BeautifulSoup111112from ..schema import Listing113from .base import BaseConnector114115BASE = "https://residentiel.agora-plateau.com"116LIST_URL = f"{BASE}/appartements/"117118# immeubles du projet (préfixe des numéros d'unité -> adresse civique)119_ADDRESSES = {120 "20": "20 Rue de Hambourg, Gatineau",121 "35": "35 Rue de Hambourg, Gatineau",122}123124# typologies des entêtes h2 -> (type d'unité Lou-Ka, chambres)125_TYPES = {126 "micro": ("Studio", 0),127 "loft": ("Loft", 0),128 "1 chambre": ("3½", 1),129 "2 chambres": ("4½", 2),130 "3 chambres": ("5½", 3),131}132133_WS_RE = re.compile(r"\s+")134_UNIT_RE = re.compile(r"^(\d+)\s*-\s*#?\s*(\w+)")135_DISPO_RE = re.compile(r"Disponibilité\s*([\d-]+)", re.I)136_DIM_RE = re.compile(r"Dimension\s*([\d\s,.]+)\s*pi", re.I)137_LOYER_RE = re.compile(r"Loyer\s*([\d\s]+)\s*\$", re.I)138_INCLUS_RE = re.compile(r"Tout-inclus\s*([\d\s]+)\s*\$", re.I)139_MENSUEL_RE = re.compile(r"Mensualité\s*([\d\s]+)\s*\$", re.I)140_TYPE_RE = re.compile(r"Type\s+([A-Z0-9+ ]+?)(?:\s+Dimension|\s+Loyer|$)")141142143def _money(m: re.Match | None) -> float | None:144 if not m:145 return None146 try:147 v = float(m.group(1).replace(" ", "").replace(" ", ""))148 except ValueError:149 return None150 return v if 100 <= v <= 20000 else None151152153def _typologie(header: str) -> tuple[str, int]:154 """Entête de section -> (type d'unité, chambres). Les variantes155 « + bureau » / « + mezzanine » gardent la même typologie de base."""156 key = _WS_RE.sub(" ", header).strip().lower()157 for prefix, val in _TYPES.items():158 if key.startswith(prefix):159 return val160 return ("", 0)161162163class JunicConnector(BaseConnector):164 source_id = "junic"165 request_delay = 0.6166 max_images = 6167168 def fetch(self) -> list[Listing]:169 html = self.get(LIST_URL).text170 soup = BeautifulSoup(html, "html.parser")171172 listings: list[Listing] = []173 header = ""174 # le DOM alterne entêtes de typologie et cartes d'unité, dans l'ordre175 for el in soup.select(".appartements_type h2, div.unit"):176 if el.name == "h2":177 header = el.get_text(" ", strip=True)178 continue179 try:180 lst = self._unit(el, header)181 if lst:182 listings.append(lst)183 except Exception:184 continue # une carte ne bloque pas le reste185186 # dédup par external_id (sécurité)187 uniq: dict[str, Listing] = {}188 for lst in listings:189 uniq.setdefault(lst.external_id, lst)190 return list(uniq.values())191192 # -- une annonce par carte d'unité -------------------------------------------193 def _unit(self, el, header: str) -> Listing | None:194 h3 = el.find("h3")195 if not h3:196 return None197 m = _UNIT_RE.match(_WS_RE.sub(" ", h3.get_text(" ", strip=True)))198 if not m:199 return None200 bldg, num = m.group(1), m.group(2)201 txt = _WS_RE.sub(" ", el.get_text(" ", strip=True))202203 unit_type, beds = _typologie(header)204 loyer = _money(_LOYER_RE.search(txt))205 inclus = _money(_INCLUS_RE.search(txt))206 mensuel = _money(_MENSUEL_RE.search(txt))207208 dispo = _DISPO_RE.search(txt)209 if dispo:210 availability = f"Libre le {dispo.group(1)}"211 elif re.search(r"MAINTENANT DISPONIBLE", txt, re.I):212 availability = "Disponible maintenant"213 else:214 availability = "Disponible"215216 area = None217 dm = _DIM_RE.search(txt)218 if dm:219 try:220 v = float(dm.group(1).replace(" ", "").replace(" ", "")221 .replace(",", "."))222 area = v if 80 <= v <= 20000 else None223 except ValueError:224 pass225226 # visite virtuelle + images (plan de l'unité, aperçu de la visite)227 details: dict = {"building": f"{bldg} Rue de Hambourg",228 "bedrooms": beds}229 images: list[str] = []230 for a in el.find_all("a", href=True):231 href = str(a["href"])232 if "tourbuzz" in href or "matterport" in href:233 details["virtual_tour"] = href234 elif href.lower().endswith(".pdf"):235 details["floor_plan"] = href # plan de l'unité (PDF)236 elif re.search(r"\.(?:jpe?g|png|webp)(?:\?|$)", href, re.I):237 if href not in images:238 images.append(href)239 for img in el.find_all("img", src=True):240 src = str(img["src"])241 if src.startswith("http") and src not in images:242 images.append(src)243 if inclus:244 details["all_inclusive_package"] = inclus245 if mensuel:246 details["total_monthly"] = mensuel247248 tm = _TYPE_RE.search(txt)249 desc_bits = [250 f"Type {tm.group(1).strip()}" if tm else header,251 f"{area:g} pi²" if area else "",252 (f"Loyer de base {loyer:g} $ + forfait tout-inclus "253 f"{inclus:g} $/mois" if loyer and inclus else ""),254 f"mensualité totale {mensuel:g} $" if mensuel else "",255 ]256 desc = " — ".join(x for x in desc_bits if x)257258 return Listing(259 source=self.source_id,260 external_id=f"{bldg}-{num}",261 url=LIST_URL,262 title=f"Agora Village Urbain ({bldg} Hambourg) — Unité {num}",263 address=_ADDRESSES.get(bldg, "Rue de Hambourg, Gatineau"),264 sector="Le Plateau",265 city="Gatineau",266 unit_type=unit_type,267 bedrooms=float(beds),268 price=loyer,269 price_label=f"{loyer:g} $ + {inclus:g} $ tout-inclus"270 if loyer and inclus else "",271 availability=availability,272 area_sqft=area,273 description=desc[:600],274 details=details,275 images=images[: self.max_images],276 )277