Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/fournelle.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0913# Last Modified : 2026-08-0914#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/fournelle.py : connecteur Appartements Fournelle (Groupe Fournelle)91# (groupefournelle.com/appartements-fournelle/ — Bécancour, Centre-du-Québec).92# Page-brochure WordPress : des blocs .item par projet (h2 + paragraphes +93# galerie swiper). Seuls les blocs affichant des lignes de prix par unité94# (« 2 × 5½ au sous-sol – 1300 $ | 2 × 5½ au RDC – 1525 $ … ») produisent des95# annonces : une annonce par ligne typologie/étage, prix et disponibilité96# (« Immeuble neuf disponible à partir du 1er Mai 2026 ») fidèles au texte.97# external_id = slug du projet + typologie + étage. 1 requête par sync.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102import unicodedata103104from bs4 import BeautifulSoup105106from ..schema import Listing, normalize_unit_type, parse_price107from .base import BaseConnector108109BASE = "https://www.groupefournelle.com"110LIST_URL = f"{BASE}/appartements-fournelle/"111112# « 2 × 5½ au sous-sol – 1300 $ » (séparateur | ; tirets – ou - ; l'étage peut113# contenir un trait d'union — « sous-sol » — d'où le prix ancré sur un chiffre)114_LINE_RE = re.compile(115 r"(\d+)\s*[×x]\s*(\d\s*(?:½|1/2))\s*(?:aux?|en)?\s*([^–|]*?)\s*[–\-]\s*(\d[\d\s]*\$)")116_AVAIL_RE = re.compile(r"disponible\s+à\s+partir\s+d[ue][^.|]*", re.I)117118119def _strip_accents(s: str) -> str:120 return "".join(c for c in unicodedata.normalize("NFD", s)121 if unicodedata.category(c) != "Mn")122123124def _slug(s: str) -> str:125 s = _strip_accents(s.lower()).replace("½", "12")126 return re.sub(r"[^a-z0-9]+", "-", s).strip("-")127128129class FournelleConnector(BaseConnector):130 source_id = "fournelle"131 request_delay = 0.7132133 def fetch(self) -> list[Listing]:134 html = self.get(LIST_URL).text135 soup = BeautifulSoup(html, "html.parser")136 listings: dict[str, Listing] = {}137 for item in soup.select("div.item"):138 content = item.select_one("div.content")139 if content is None:140 continue141 try:142 self._parse_block(item, content, listings)143 except Exception:144 continue145 return list(listings.values())146147 def _parse_block(self, item, content, listings: dict[str, Listing]) -> None:148 h2 = content.find("h2")149 block_title = re.sub(r"\s+", " ", h2.get_text(" ", strip=True)) if h2 else ""150 link = content.select_one("a[href]")151 project = _slug((link["href"] if link else "").strip("/")) or _slug(block_title)152153 text = re.sub(r"\s+", " ", content.get_text(" ", strip=True))154 lines = _LINE_RE.findall(text)155 if not lines:156 return # bloc informatif sans prix : pas d'annonce157158 m_av = _AVAIL_RE.search(text)159 availability = re.sub(r"\s+", " ", m_av.group(0)).strip() if m_av else ""160161 # caractéristiques (liste <ul>) + phrases de conditions (sans fumée…)162 feats = [re.sub(r"\s+", " ", li.get_text(" ", strip=True))163 for li in content.find_all("li")]164 conditions = [re.sub(r"\s+", " ", p.get_text(" ", strip=True))165 for p in content.find_all("p")166 if re.search(r"sans fumée|sans animaux|enquête de crédit|"167 r"stationnement inclus|chauffé", p.get_text(), re.I)]168 description = "\n".join([block_title] + conditions)[:900]169170 # galerie swiper du bloc (photos + plans, pleine taille)171 images: list[str] = []172 for a in item.select(".swiper-slide a[href]"):173 u = a["href"]174 if u.startswith("http") and re.search(r"\.(jpe?g|png|webp)$", u, re.I) \175 and u not in images:176 images.append(u)177178 for qty, utype, floor, price in lines:179 floor = floor.strip(" .,")180 ext = _slug(f"{project}-{utype}-{floor}")181 if ext in listings:182 continue183 label = f"{utype} {('au ' + floor) if floor else ''}".strip()184 listings[ext] = Listing(185 source=self.source_id,186 external_id=ext,187 url=LIST_URL,188 title=f"{label} — {block_title}",189 city="Bécancour", # page « Appartements à louer à Bécancour »190 unit_type=normalize_unit_type(utype),191 price=parse_price(price),192 price_label=price.strip(),193 availability=availability,194 description=description,195 amenities=feats[:20],196 details={"project": project, "floor": floor,197 "units_on_line": qty},198 images=images[:15],199 )200