Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/jcl.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/jcl.py : connecteur petites annonces Groupe JCL91# (annonces.groupejcl.com) — journal local des Basses-Laurentides / Rive-Nord92# (Sainte-Thérèse, Saint-Jérôme, Saint-Eustache et environs). WordPress +93# plugin « Classified Listing » (rtcl) rendu serveur : on ne moissonne QUE la94# catégorie immobilier/logements-a-louer (cartes .rtcl-listing-item : titre,95# prix, localité, lien). La page détail (.rtin-des / .rtin-location) fournit96# description, adresse et photos. Granularité : annonce (unité).97# ⚠️ Portail de petites annonces de particuliers : certaines annonces restent98# affichées longtemps — Lou-Ka les reprend telles qu'affichées par la source.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing107from .base import BaseConnector108109BASE = "https://annonces.groupejcl.com"110CAT_URL = f"{BASE}/categories/immobilier/logements-a-louer/"111MAX_PAGES = 10112113IMG_RE = re.compile(114 r"https://annonces\.groupejcl\.com/wp-content/uploads/classified-listing/"115 r"[^\"'\s\\]+\.(?:jpe?g|png|webp)", re.I)116THUMB_RE = re.compile(r"-\d{2,4}x\d{2,4}(?=\.(?:jpe?g|png|webp)$)", re.I)117PRICE_RE = re.compile(r"(\d[\d\s,.]*)\s*\$?")118REGION_RE = re.compile(r"\s+et\s+environs\s*$", re.I)119120121class JclConnector(BaseConnector):122 source_id = "jcl"123 request_delay = 0.8124 max_images = 10125126 # -- page détail (cachée en BD via self.detail) ---------------------------127 def _detail(self, url: str) -> dict:128 try:129 html = self.get(url).text130 except Exception:131 return {}132 soup = BeautifulSoup(html, "html.parser")133 payload: dict = {}134135 el = soup.select_one(".rtin-content-area .rtin-content")136 if el is not None:137 payload["description"] = re.sub(138 r"\s+", " ", el.get_text(" ", strip=True))[:1500]139140 # « 367 rue leonard | Saint-Jérôme et environs, Québec »141 for el in soup.select(".rtin-location"):142 parts = [p.strip() for p in143 el.get_text("|", strip=True).split("|") if p.strip()]144 street = [p for p in parts145 if not re.search(r"et environs|Québec$", p, re.I)]146 if street:147 payload["address"] = street[0]148 break149150 imgs = []151 for u in dict.fromkeys(IMG_RE.findall(html)):152 full = THUMB_RE.sub("", u)153 if full not in imgs:154 imgs.append(full)155 payload["images"] = imgs[: self.max_images]156 return payload157158 # -- fetch -----------------------------------------------------------------159 def fetch(self) -> list[Listing]:160 listings: list[Listing] = []161 seen: set[str] = set()162163 for page in range(1, MAX_PAGES + 1):164 url = CAT_URL if page == 1 else f"{CAT_URL}page/{page}/"165 try:166 html = self.get(url).text167 except Exception:168 break169 soup = BeautifulSoup(html, "html.parser")170 items = soup.select(".rtcl-listing-item")171 if not items:172 break173174 new_on_page = 0175 for it in items:176 a = it.select_one(".rtin-title a[href]")177 if a is None:178 continue179 href = a["href"].split("?")[0]180 slug = href.rstrip("/").rsplit("/", 1)[-1]181 if not slug or slug in seen:182 continue183 seen.add(slug)184 new_on_page += 1185186 title = re.sub(r"\s+", " ", a.get_text(" ", strip=True))187188 price = None189 price_label = ""190 el = it.select_one(".rtcl-price-amount")191 if el is not None:192 price_label = re.sub(r"\s+", " ",193 el.get_text(" ", strip=True))194 m = PRICE_RE.search(price_label.replace(",", ""))195 if m:196 try:197 val = float(m.group(1).replace(" ", "")198 .replace(" ", ""))199 if 300 <= val <= 20000:200 price = val201 except ValueError:202 pass203204 # localité : lien /listing-location/quebec/<ville>/205 city = ""206 loc = it.select_one('a[href*="/listing-location/"]')207 if loc is not None:208 city = REGION_RE.sub(209 "", loc.get_text(" ", strip=True)).strip()210211 key = f"{title}|{price_label}|{city}"212 det = self.detail(slug, key, lambda u=href: self._detail(u))213214 listings.append(Listing(215 source=self.source_id,216 external_id=slug,217 url=href,218 title=title,219 address=det.get("address", ""),220 city=city,221 price=price,222 price_label=price_label,223 description=det.get("description", ""),224 images=list(det.get("images") or []),225 ))226 if new_on_page == 0:227 break228 return listings229