Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/construction_app.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/construction_app.py : connecteur Construction APP / Les91# Habitations APP (constructionappinc.com) — constructeur de Portneuf qui92# loue ses immeubles à Pont-Rouge, Donnacona, Saint-Marc-des-Carrières,93# Portneuf, Saint-Basile, Val-Bélair et Sainte-Catherine-de-la-J.-Cartier.94# WordPress/Divi rendu serveur : /vente-et-location/ empile des blocs95# `.et_pb_row` — h1 « Ville (Québec) », libellé « LOGEMENT À LOUER »/96# « MAISONS DE VILLE EN LOCATION », adresse, caractéristiques (chambres,97# sdb, types n ½) et photos. Ni prix ni date (Tier B).98# Granularité : immeuble (un bloc = une annonce).99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from bs4 import BeautifulSoup105106from ..schema import Listing, strip_accents107from .base import BaseConnector108109BASE = "https://www.constructionappinc.com"110LIST_URL = f"{BASE}/vente-et-location/"111112LABEL_RE = re.compile(r"(LOGEMENTS?|MAISONS? DE VILLE)"113 r".{0,40}(À LOUER|EN LOCATION)", re.I | re.S)114CITY_RE = re.compile(r"^(.+?)\s*\(Qu[ée]bec\)$", re.I)115ADDR_RE = re.compile(r"^\d[\d\s\wàâéèêëîïôùûç.'-]*,\s*.+", re.I)116ADDR2_RE = re.compile(r"^(rue|avenue|av\.|boul)", re.I)117BED_RE = re.compile(r"Chambre\(?s?\)?\s*:\s*(\d+)", re.I)118BATH_RE = re.compile(r"Salle\(?s?\)?\s*de\s*bain\s*:\s*(\d+)", re.I)119TYPE_RE = re.compile(r"\b(\d)\s*1/2\b")120121CONTACT = {"email": "info@habitationsapp.com", "phone": "418-410-0715"}122123124def _slug(text: str) -> str:125 return re.sub(r"-+", "-",126 re.sub(r"[^a-z0-9]+", "-", strip_accents(text.lower()))127 ).strip("-")128129130class ConstructionAppConnector(BaseConnector):131 source_id = "construction_app"132 request_delay = 0.6133134 def fetch(self) -> list[Listing]:135 listings: list[Listing] = []136 try:137 html = self.get(LIST_URL).text138 except Exception:139 return listings140 soup = BeautifulSoup(html, "html.parser")141142 seen: set[str] = set()143 for row in soup.select("div.et_pb_row"):144 try:145 lst = self._parse_row(row, seen)146 except Exception:147 continue148 if lst is not None:149 listings.append(lst)150 return listings151152 def _parse_row(self, row, seen: set[str]) -> Listing | None:153 txt = row.get_text("\n", strip=True)154 if not LABEL_RE.search(txt):155 return None156 lines = [ln.strip() for ln in txt.split("\n") if ln.strip()]157158 city = ""159 for ln in lines:160 m = CITY_RE.match(ln)161 if m:162 city = m.group(1).strip()163 break164165 address = next(166 (ln for ln in lines167 if ADDR_RE.match(ln) and not ln.lower().startswith(("t 4", "418"))168 and "1/2" not in ln), "")169 if not address:170 address = next((ln for ln in lines171 if ADDR2_RE.match(ln) and "," in ln), "")172 if not address:173 return None # bloc générique sans adresse174 if not city: # ville = dernier segment de l'adresse175 tail = address.split(",")[-1].strip()176 if tail and not re.match(r"^suite", tail, re.I):177 city = tail178179 ext_id = _slug(address)180 if not ext_id or ext_id in seen:181 return None182 seen.add(ext_id)183184 blob = " | ".join(lines)185 bedrooms = bathrooms = None186 m = BED_RE.search(blob)187 if m:188 bedrooms = float(m.group(1))189 m = BATH_RE.search(blob)190 if m:191 bathrooms = float(m.group(1))192 types = list(dict.fromkeys(f"{n}½" for n in TYPE_RE.findall(blob)))193 unit_type = types[0] if len(types) == 1 else ""194195 # commodités : lignes courtes ni adresse/ville/label/contacts196 amenities = [ln for ln in lines197 if 3 < len(ln) <= 60198 and ln not in (address, city)199 and not CITY_RE.match(ln)200 and not LABEL_RE.search(ln)201 and not re.search(r"(chambre|salle|1/2|@|\d{3}[ -]\d{4}"202 r"|nouveau projet|contactez|photos?\b"203 r"|plans? des|en savoir)",204 ln, re.I)][:12]205206 images = [img.get("src", "") for img in row.find_all("img")207 if img.get("src", "").startswith("http")208 and "icon" not in img.get("src", "").lower()209 and "logo" not in img.get("src", "").lower()][:10]210211 label = "MAISONS DE VILLE" if re.search(r"maisons? de ville",212 blob, re.I) else "Logement"213 return Listing(214 source=self.source_id,215 external_id=ext_id,216 url=LIST_URL,217 title=f"{address}",218 address=f"{address}" + (f", {city}" if city219 and city.lower() not in address.lower()220 else ""),221 city=city,222 unit_type=unit_type,223 bedrooms=bedrooms,224 bathrooms=bathrooms,225 price_label="Prix sur demande",226 availability="Disponible",227 description=f"{label} à louer au {address} ({city}) — "228 "Les Habitations APP (Construction APP). "229 + (f"Types offerts : {', '.join(types)}. "230 if types else "") + " ".join(amenities[:6]),231 amenities=amenities,232 details={"contact": dict(CONTACT),233 **({"types": types} if len(types) > 1 else {})},234 images=images,235 )236