Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/novelo.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0913# Last Modified : 2026-09-1014#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/novelo.py : connecteur Les Appartements Novelo inc.91# (appartementsnovelo.com — Saguenay, secteur Jonquière/Arvida ; projet du92# Groupe Dumont, ~50-100 appartements rénovés). WordPress + Elementor + WPML,93# tout rendu serveur sur une page unique /louer-un-appartement/ : une section94# par type d'unité (« Appartement — Loft », « — 3 1/2 », « — 4 1/2 »,95# « — 5 1/2 ») avec prix « À partir de 901$/ mois », description, liste des96# services offerts et galerie. Granularité par TYPE (pas d'unités97# individuelles ni de dates) — types, prix et photos réels, précédent98# immeubles_guillot. Adresse du complexe : rue Langelier, Saguenay.99# robots.txt WP standard (wp-admin seulement), sitemap.100# -----------------------------------------------------------------------------101from __future__ import annotations102103import re104105from bs4 import BeautifulSoup106107from ..schema import Listing, normalize_unit_type, parse_price, strip_accents108from .base import BaseConnector109110BASE = "https://appartementsnovelo.com"111LIST_URL = f"{BASE}/louer-un-appartement/"112113_HEAD_RE = re.compile(r"^Appartement\s*[—–-]\s*(.+)$", re.I)114_PRICE_RE = re.compile(r"À partir de\s*\d[\d\s]*\$\s*(?:/\s*mois)?", re.I)115# suffixe de redimensionnement WordPress (« -300x200.jpg » -> pleine taille)116_SIZE_SUFFIX = re.compile(r"-\d{2,4}x\d{2,4}(?=\.(?:jpg|jpeg|png|webp)$)", re.I)117118119def _slugify(label: str) -> str:120 """« 4 1/2 » -> « 4-1-2 » ; « Loft » -> « loft » (identifiant stable)."""121 return re.sub(r"[^a-z0-9]+", "-", strip_accents(label.lower())).strip("-")122123124class NoveloConnector(BaseConnector):125 source_id = "novelo"126 request_delay = 0.6127128 def fetch(self) -> list[Listing]:129 html = self.get(LIST_URL).text130 soup = BeautifulSoup(html, "html.parser")131132 listings: dict[str, Listing] = {}133 # une section Elementor de premier niveau par type d'appartement134 for h in soup.find_all("h2"):135 m = _HEAD_RE.match(h.get_text(" ", strip=True))136 if not m:137 continue138 try:139 self._parse_section(h, m.group(1).strip(), listings)140 except Exception:141 continue142 # échec HONNÊTE : une page saine affiche TOUJOURS les 4 sections par143 # type (granularité par type, jamais de vrai zéro) — un rendu partiel144 # servi 200 doit lever (ok=0) et non dépublier les annonces via un145 # « 0 trouvé ok » (vu le 2026-09-10 19:19, missed=4)146 if not listings:147 raise RuntimeError(148 "appartementsnovelo.com : aucune section « Appartement — … » "149 "parsée (rendu partiel ou page restructurée)")150 return list(listings.values())151152 # -- section « Appartement — <type> » ---------------------------------------------153 def _parse_section(self, heading, unit_label: str,154 listings: dict[str, Listing]) -> None:155 ext_id = _slugify(unit_label)156 if not ext_id or ext_id in listings:157 return158159 # remonter à la section Elementor de premier niveau160 sec = heading161 while sec.parent is not None and sec.name != "section":162 sec = sec.parent163 if sec.name != "section":164 return165166 # prix « À partir de 901$/ mois » (le plus bas du type)167 price_label = ""168 m = _PRICE_RE.search(sec.get_text(" ", strip=True))169 if m:170 price_label = re.sub(r"\s+", " ", m.group(0)).strip()171172 # description : paragraphes de la section (hors mentions de contact)173 paras: list[str] = []174 for p in sec.find_all("p"):175 txt = re.sub(r"\s+", " ", p.get_text(" ", strip=True))176 if not txt or _PRICE_RE.search(txt):177 continue178 if re.search(r"contactez|enquête de crédit|418-|courriel", txt, re.I):179 continue180 paras.append(txt)181 description = "\n".join(paras)[:1500]182183 # services offerts / caractéristiques : items de liste de la section184 amenities: list[str] = []185 for li in sec.find_all("li"):186 txt = re.sub(r"\s+", " ", li.get_text(" ", strip=True))187 if txt and txt not in amenities:188 amenities.append(txt)189190 # galerie de la section (photos réelles, pleine taille)191 images: list[str] = []192 for img in sec.find_all("img", src=True):193 u = img["src"]194 if not u.startswith("http") or "/wp-content/uploads/" not in u:195 continue196 u = _SIZE_SUFFIX.sub("", u)197 if u not in images:198 images.append(u)199200 listings[ext_id] = Listing(201 source=self.source_id,202 external_id=ext_id,203 url=f"{LIST_URL}#{ext_id}",204 title=f"Appartement {unit_label} — Les Appartements Novelo",205 address="2469, rue Langelier", # complexe (bureau de location)206 city="Saguenay",207 unit_type=normalize_unit_type(unit_label),208 price=parse_price(price_label.replace("À partir de", "").strip()),209 price_label=price_label,210 description=description,211 amenities=amenities[:20],212 images=images[:25],213 )214