Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/gerik.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/gerik.py : connecteur Gerik (gerik.ca) — Outaouais91# Promoteur/gestionnaire de Gatineau (Hull-Aylmer, Gatineau, Cantley,92# Masson-Angers). WordPress/WPBakery rendu serveur : la page93# /appartements-a-louer-gatineau/ liste les projets locatifs en cartes94# (h2 nom du projet + méta « Hull-Aylmer · Studios, 1 et 2 chambres ·95# Disponible dès maintenant » + description + lien /projets/<slug>/).96# AUCUN prix publié nulle part (ni carte, ni fiche projet) : on remplit97# availability et on laisse price/price_label vides. Granularité = projet ×98# typologie (studio / n chambres) — le site n'expose pas d'inventaire par99# unité. Seuls les projets marqués « Disponible » sont retenus (les projets100# « À VENIR » / « En construction » / « en développement » sont exclus).101# Photos : classes CSS vc_custom_* (background-image) mappées aux cartes.102# external_id = <slug du projet>-<typologie> — stable.103# -----------------------------------------------------------------------------104from __future__ import annotations105106import re107108from bs4 import BeautifulSoup109110from ..schema import Listing, strip_accents111from .base import BaseConnector112113BASE = "https://gerik.ca"114LIST_URL = f"{BASE}/appartements-a-louer-gatineau/"115116BG_RE = re.compile(r"\.(vc_custom_\w+)\{background-image:\s*url\(([^)?\s]+)")117TYPES_RE = re.compile(r"Studios?|(\d+)(?:,\s*\d+)*(?:\s*et\s*\d+)?\s*chambres?",118 re.I)119SEP = "·"120121# secteur affiché sur la carte -> (secteur Lou-Ka, ville)122PLACES = {123 "hull-aylmer": ("Aylmer", "Gatineau"),124 "aylmer": ("Aylmer", "Gatineau"),125 "hull": ("Hull", "Gatineau"),126 "gatineau": ("", "Gatineau"),127 "masson-angers": ("Masson-Angers", "Gatineau"),128 "cantley": ("", "Cantley"),129 "chelsea": ("", "Chelsea"),130}131132133def _slug(text: str) -> str:134 s = strip_accents(text.lower())135 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")136137138class GerikConnector(BaseConnector):139 source_id = "gerik"140 request_delay = 0.8141142 def fetch(self) -> list[Listing]:143 html = self.get(LIST_URL).text144 soup = BeautifulSoup(html, "html.parser")145 bg_map = dict(BG_RE.findall(html)) # classe vc_custom_* -> photo146147 listings: list[Listing] = []148 seen: set[str] = set()149 for h2 in soup.find_all("h2"):150 name = re.sub(r"\s+", " ", h2.get_text(" ", strip=True))151 if not name or "Aucun projet" in name or "Découvrez" in name \152 or "partenaire" in name:153 continue154 row = h2155 for _ in range(8): # remonter à la rangée du projet156 row = row.parent157 if row is None:158 break159 if "vc_row" in (row.get("class") or []):160 break161 if row is None or "vc_row" not in (row.get("class") or []):162 continue163 try:164 listings.extend(self._parse_project(name, row, bg_map, seen))165 except Exception:166 continue167 return listings168169 def _parse_project(self, name: str, row, bg_map: dict,170 seen: set[str]) -> list[Listing]:171 proj_slug = _slug(name)172 if proj_slug in seen:173 return []174 seen.add(proj_slug)175176 text = re.sub(r"\s+", " ", row.get_text(" | ", strip=True))177 # méta « Hull-Aylmer · Studios, 1 et 2 chambres · Disponible … »178 meta_el = row.find(string=re.compile(SEP))179 meta = re.sub(r"\s+", " ", str(meta_el)).strip() if meta_el else ""180 parts = [p.strip() for p in meta.split(SEP) if p.strip()]181182 availability = next((p for p in parts183 if re.search(r"disponible", p, re.I)), "")184 if not availability:185 return [] # à venir / en construction186187 sector, city = "", "Gatineau"188 if parts:189 key = strip_accents(parts[0].lower()).strip()190 sector, city = PLACES.get(key, (parts[0], "Gatineau"))191192 # typologies : « Studios, 1 et 2 chambres » -> Studio, 1 ch, 2 ch193 types: list[tuple[str, float | None]] = []194 types_part = next((p for p in parts195 if re.search(r"studio|chambre", p, re.I)), "")196 if re.search(r"studio", types_part, re.I):197 types.append(("Studio", None))198 nums = re.findall(r"\d+", re.sub(r"\d+\s*unités?", "", types_part))199 for n in nums:200 types.append((f"{n} chambres" if int(n) > 1 else "1 chambre",201 float(n)))202 if not types:203 types = [("", None)]204205 # description : paragraphe le plus long de la carte206 description = ""207 for p in row.find_all("p"):208 t = re.sub(r"\s+", " ", p.get_text(" ", strip=True))209 if len(t) > len(description) and SEP not in t:210 description = t211 description = description[:1200]212213 url = LIST_URL214 a = row.find("a", href=re.compile(r"/projets/"))215 if a:216 url = a["href"]217 if not url.startswith("http"):218 url = BASE + url219220 images: list[str] = []221 for el in row.select("[class*='vc_custom_']"):222 for cls in (el.get("class") or []):223 u = bg_map.get(cls)224 if u and u not in images:225 images.append(u)226227 details: dict = {}228 units_part = next((p for p in parts229 if re.search(r"\d+\s*unités?", p, re.I)), "")230 m = re.search(r"(\d+)\s*unités?", units_part, re.I)231 if m:232 details["building_units"] = int(m.group(1))233234 listings = []235 for label, beds in types:236 suffix = "studio" if label == "Studio" else \237 f"{int(beds)}ch" if beds else "logement"238 listings.append(Listing(239 source=self.source_id,240 external_id=f"{proj_slug}-{suffix}",241 url=url,242 title=f"{name} — {label}" if label else name,243 address="",244 sector=sector,245 city=city,246 unit_type="Studio" if label == "Studio" else "",247 bedrooms=beds,248 availability=availability,249 description=description,250 details=dict(details),251 images=list(images),252 ))253 return listings254