Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/place_barrage.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/place_barrage.py : connecteur Place du Barrage (placedubarrage.com)91# Immeuble locatif au 2, rue Vertu à Windsor (Estrie), géré par Sphère92# immobilier. Site Wix rendu serveur : la page /appartements liste 24 cartes93# (répéteur Wix « wixui-repeater__item ») — « Appartement 101-A », courte94# description, prix (« 1475$ ») ou « LOUÉ », lien vers la fiche95# /appartements/appartement-<no>-<lettre>. ⚠️ Le <title> du gabarit Wix96# mentionne un autre projet (Le Connaught) : ignorer. On dérive l'URL de la97# fiche du numéro affiché sur la carte (les hrefs peuvent être désalignés).98# Granularité : unité ; prix affichés, typologies non publiées.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from .base import BaseConnector107from ..schema import Listing108109BASE = "https://www.placedubarrage.com"110LIST_URL = f"{BASE}/appartements"111112ADDRESS = "2, rue Vertu, Windsor"113CITY = "Windsor"114115UNIT_RE = re.compile(r"^Appartement\s+(\d{3})-([A-F])$", re.I)116PRICE_RE = re.compile(r"^(\d{3,4})\s*\$$")117IMG_RE = re.compile(r'https://static\.wixstatic\.com/media/'118 r'[^"\s\\)]+\.(?:jpe?g|png|webp)[^"\s\\)]*', re.I)119120FLOOR_BY_DIGIT = {"1": "Étage 1", "2": "Étage 2", "3": "Étage 3"}121122123class PlaceBarrageConnector(BaseConnector):124 source_id = "place_barrage"125 request_delay = 0.6126127 def fetch(self) -> list[Listing]:128 listings: list[Listing] = []129 try:130 html = self.get(LIST_URL).text131 except Exception:132 return listings133 soup = BeautifulSoup(html, "html.parser")134135 for item in soup.select("div.wixui-repeater__item"):136 try:137 text_lines = [t.strip() for t in138 item.get_text("\n", strip=True).split("\n")]139 unit_no, letter = "", ""140 for t in text_lines:141 m = UNIT_RE.match(t)142 if m:143 unit_no, letter = m.group(1), m.group(2).upper()144 break145 if not unit_no:146 continue147 if any(re.search(r"^lou[ée]$", t, re.I) for t in text_lines):148 continue # déjà loué149 price = None150 for t in text_lines:151 mp = PRICE_RE.match(t)152 if mp:153 price = float(mp.group(1))154 break155 if price is None:156 continue # ni prix ni LOUÉ : statut inconnu157158 description = next(159 (t for t in text_lines160 if t.lower().startswith("appartement situé")), "")161162 images = [u.split("/v1/")[0] for u in163 dict.fromkeys(IMG_RE.findall(str(item)))][:15]164165 # ⚠️ hrefs Wix désalignés (la carte 302-E pointe vers la fiche166 # 302-a…) et seules les fiches -a/-b/-f existent : on ne garde167 # la fiche que si sa lettre correspond à celle de la carte,168 # sinon l'URL de l'annonce est la page liste.169 url = LIST_URL170 a = item.select_one('a[href*="/appartements/appartement-"]')171 if a and a.get("href", "").rstrip("/").endswith(172 f"-{unit_no}-{letter.lower()}"):173 url = a["href"].rstrip("/")174 ext_id = f"{unit_no}-{letter}".lower()175 if any(l.external_id == ext_id for l in listings):176 continue177 listings.append(Listing(178 source=self.source_id,179 external_id=ext_id,180 url=url,181 title=f"Appartement {unit_no}-{letter} — "182 f"Place du Barrage",183 address=ADDRESS,184 city=CITY,185 price=price,186 availability="Disponible",187 description=description,188 details={"floor": FLOOR_BY_DIGIT.get(unit_no[0], "")},189 images=images,190 ))191 except Exception:192 continue193 return listings194