Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/lequerre.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/lequerre.py : connecteur Habitations L'Équerre91# (habitationslequerre.com) — OBNL d'habitation de Sherbrooke (34 immeubles92# abordables, logement locatif privé consultable, pas du HLM). WordPress,93# mais la page /immeubles/ est un gabarit maison (Tailwind) rendu serveur :94# une <section class="building-section"> par immeuble vedette, dont le95# data-category vaut « disponibles » quand l'immeuble a des unités à louer —96# badge « DISPONIBLE MAINTENANT - 735$ / mois », h2 (type de logements),97# h3 (adresse civique), paragraphe descriptif et visuel en arrière-plan.98# Seules les sections « disponibles » deviennent des annonces (granularité99# immeuble : le site ne publie pas d'unités individuelles datées).100# external_id = version normalisée de l'adresse (stable).101# -----------------------------------------------------------------------------102from __future__ import annotations103104import re105import unicodedata106107from bs4 import BeautifulSoup108109from ..schema import Listing, normalize_unit_type, parse_price110from .base import BaseConnector111112BASE = "https://habitationslequerre.com"113LIST_URL = f"{BASE}/immeubles/"114115116def _slugify(text: str) -> str:117 t = unicodedata.normalize("NFKD", text).encode("ascii", "ignore").decode()118 t = re.sub(r"[^a-z0-9]+", "-", t.lower()).strip("-")119 return t or "immeuble"120121122def _clean_unit_type(raw: str) -> str:123 if re.search(r"\bstudios?\b", raw or "", re.I):124 return "Studio"125 ut = normalize_unit_type(raw or "")126 if re.fullmatch(r"\d½\+?|6½\+|Studio|Loft|Chambre|Maison", ut or ""):127 return ut128 return ""129130131class LequerreConnector(BaseConnector):132 source_id = "lequerre"133 request_delay = 0.7134135 def fetch(self) -> list[Listing]:136 html = self.get(LIST_URL).text137 soup = BeautifulSoup(html, "html.parser")138139 listings: dict[str, Listing] = {}140 for sec in soup.select("section.building-section"):141 cats = (sec.get("data-category") or "").lower()142 if "disponibles" not in cats:143 continue # immeuble sans unité à louer actuellement144 try:145 lst = self._parse_section(sec)146 except Exception:147 continue148 if lst and lst.external_id not in listings:149 listings[lst.external_id] = lst150 return list(listings.values())151152 def _parse_section(self, sec) -> Listing | None:153 h2 = sec.select_one("h2")154 h3 = sec.select_one("h3")155 title = re.sub(r"\s+", " ", h2.get_text(" ", strip=True)).strip() \156 if h2 else ""157 address_full = re.sub(r"\s+", " ", h3.get_text(" ", strip=True)).strip() \158 if h3 else ""159 if not (title or address_full):160 return None161162 # « 14, rue Jean-Maurice, Sherbrooke » -> adresse + ville163 address, city = address_full, ""164 m = re.match(r"^(.*),\s*(Sherbrooke)\s*$", address_full, re.I)165 if m:166 address, city = m.group(1).strip(), m.group(2)167168 # badge « DISPONIBLE MAINTENANT - 735$ / mois »169 badge = ""170 for div in sec.find_all("div"):171 t = div.get_text(" ", strip=True)172 if re.match(r"^\s*DISPONIBLE", t or "", re.I) and len(t) < 90:173 badge = re.sub(r"\s+", " ", t).strip()174 break175 availability, price_label = badge, ""176 if "-" in badge:177 availability, _, price_label = (p.strip() for p in178 badge.partition("-"))179180 # paragraphe descriptif181 description = ""182 p = sec.select_one("p")183 if p:184 description = re.sub(r"\s+", " ",185 p.get_text(" ", strip=True)).strip()[:1500]186187 # visuel : background-image de la colonne photo188 images: list[str] = []189 bg = sec.select_one("[style*=background-image]")190 if bg:191 m_img = re.search(r"url\('([^']+)'\)", bg.get("style") or "")192 if m_img and m_img.group(1).startswith("http"):193 images = [m_img.group(1)]194195 return Listing(196 source=self.source_id,197 external_id=_slugify(address or title),198 url=LIST_URL,199 title=title or address_full,200 address=address,201 city=city,202 unit_type=_clean_unit_type(title),203 price=parse_price(price_label),204 price_label=price_label,205 availability=availability,206 description=description,207 images=images,208 )209