Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/nelson.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/nelson.py : connecteur Le Nelson (lenelson.com)91# Immeuble locatif de 5 étages au 111, rue Jean-Besré à Cowansville92# (Brome-Missisquoi). Site PHP statique rendu serveur : une page par étage93# (/appartements-a-louer/logements-a-louer-cowansville-<etage>) avec, pour94# chaque unité, un lien porteur de data-attributes (data-appt, data-area,95# data-room, data-bathroom, data-pdf, data-availability, data-type).96# ⚠️ HTTPS obligatoire (les URL http bouclent en 301) et User-Agent complet97# requis (406 sinon — géré par l'escalade de BaseConnector). Granularité :98# unité ; on ne retient que celles non « LOUÉ ». Prix non publiés.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from .base import BaseConnector107from ..schema import Listing, normalize_unit_type108109BASE = "https://lenelson.com"110FLOOR_PAGES = [111 ("premiere-etage", 1),112 ("deuxieme-etage", 2),113 ("troisieme-etage", 3),114 ("quatrieme-etage", 4),115 ("cinquieme-etage", 5),116]117118ADDRESS = "111, rue Jean-Besré, Cowansville"119CITY = "Cowansville"120121SQFT_RE = re.compile(r"(\d{3,4})")122UA = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "123 "(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36")124125126class NelsonConnector(BaseConnector):127 source_id = "nelson"128 request_delay = 0.6129130 def fetch(self) -> list[Listing]:131 listings: list[Listing] = []132 for slug, floor in FLOOR_PAGES:133 url = (f"{BASE}/appartements-a-louer/"134 f"logements-a-louer-cowansville-{slug}")135 try:136 html = self.get(url, headers={"User-Agent": UA}).text137 except Exception:138 continue139 soup = BeautifulSoup(html, "html.parser")140141 for a in soup.select("a[data-appt]"):142 try:143 unit_no = (a.get("data-appt") or "").strip()144 if not unit_no:145 continue146 availability = (a.get("data-availability") or "").strip()147 if re.search(r"lou[ée]", availability, re.I):148 continue # déjà loué149 unit_type = normalize_unit_type(150 (a.get("data-type") or "").strip())151 sqft = None152 ms = SQFT_RE.search(a.get("data-area") or "")153 if ms:154 sqft = float(ms.group(1))155 bedrooms = bathrooms = None156 if (a.get("data-room") or "").isdigit():157 bedrooms = int(a["data-room"])158 if (a.get("data-bathroom") or "").isdigit():159 bathrooms = int(a["data-bathroom"])160161 details: dict = {"floor": f"Étage {floor}"}162 pdf = (a.get("data-pdf") or "").strip()163 if pdf:164 details["plan_pdf"] = (pdf if pdf.startswith("http")165 else BASE + pdf)166 images: list[str] = []167 thumb = (a.get("data-thumbnail") or "").strip()168 if thumb and "default-thumbnail" not in thumb:169 images.append(thumb if thumb.startswith("http")170 else BASE + thumb)171172 ext_id = f"logement-{unit_no}"173 if any(l.external_id == ext_id for l in listings):174 continue175 listings.append(Listing(176 source=self.source_id,177 external_id=ext_id,178 url=url,179 title=f"Logement {unit_no}"180 + (f" ({unit_type})" if unit_type else "")181 + " — Le Nelson",182 address=ADDRESS,183 city=CITY,184 unit_type=unit_type,185 bedrooms=bedrooms,186 bathrooms=bathrooms,187 availability=availability or "Disponible",188 area_sqft=sqft,189 details=details,190 images=images,191 ))192 except Exception:193 continue194 return listings195