Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/elements.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0613# Last Modified : 2026-08-0814#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/elements.py : connecteur Quartier les Éléments91# (quartierleselements.com — Lévis, secteur Saint-Romuald, 5 phases).92# Navigation : phase -> étage (plan interactif <area data-available>)93# -> fiche d'unité (type, superficie, prix).94# -----------------------------------------------------------------------------95from __future__ import annotations9697import re9899from bs4 import BeautifulSoup100101from ..schema import Listing, infer_city, normalize_unit_type, parse_price102from .base import BaseConnector103104BASE = "https://www.quartierleselements.com"105ROOT = f"{BASE}/appartements-condos-locatifs-levis"106SECTOR = "Saint-Romuald"107ADDRESS = "1432, rue de Jupiter, Lévis"108# Bureau de location affiché sur chaque fiche d'unité109CONTACT = {"phone": "581-922-3334", "email": "info@quartierleselements.com"}110111112class ElementsConnector(BaseConnector):113 source_id = "elements"114 request_delay = 0.5115 max_floor_pages = 40 # garde-fou116117 def fetch(self) -> list[Listing]:118 # 1) Découvrir les pages d'étages de chaque phase119 floor_urls: list[str] = []120 for phase in range(1, 6):121 try:122 html = self.get(f"{ROOT}/phase-{phase}/").text123 except Exception:124 continue125 for path in sorted(set(re.findall(126 rf'href="(/appartements-condos-locatifs-levis/'127 rf'phase-{phase}/etage-\d+/)"', html))):128 floor_urls.append(BASE + path)129130 # 2) Repérer les unités disponibles sur les plans d'étages131 unit_urls: list[str] = []132 for url in floor_urls[:self.max_floor_pages]:133 try:134 html = self.get(url).text135 except Exception:136 continue137 for tag in re.findall(r"<area\b[^>]*>", html, re.S):138 if 'data-available="1"' not in tag:139 continue140 m = re.search(r'href="([^"]+)"', tag)141 if m and m.group(1) not in unit_urls:142 unit_urls.append(m.group(1))143144 # 3) Fiche de chaque unité disponible145 listings: list[Listing] = []146 for path in unit_urls:147 full_url = path if path.startswith("http") else BASE + path148 try:149 html = self.get(full_url).text150 except Exception:151 continue152 try:153 soup = BeautifulSoup(html, "html.parser")154 text = soup.get_text("\n", strip=True)155156 num = re.search(r"Unité\s+(\w+)", text)157 unit_no = num.group(1) if num else path.strip("/").split("/")[-1]158 phase_m = re.search(r"phase-(\d)", path)159 phase = phase_m.group(1) if phase_m else "?"160161 type_m = re.search(r"Grandeur\s*:\s*([^\n]+)", text)162 unit_type = normalize_unit_type(type_m.group(1)) if type_m else ""163164 prix_line = ""165 pm = re.search(r"Prix\s*:\s*([^\n]+)", text)166 price = None167 if pm:168 prix_line = pm.group(1).strip()169 price = parse_price(prix_line)170171 availability = "Disponible"172 am = re.search(r"pour\s+([a-zû]+\s+20\d\d)", prix_line, re.I)173 if am:174 availability = f"Disponible ({am.group(1)})"175176 # superficies structurées : la brute = superficie du logement177 # (le parsing générique prendrait le min, donc la terrasse)178 area_sqft = None179 desc_parts = []180 for label in ("Superficie brute", "Superficie terrasse",181 "Superficie totale"):182 dm = re.search(rf"{label}\s*:\s*([^\n]+)", text)183 if dm:184 desc_parts.append(f"{label} : {dm.group(1).strip()}")185 if label == "Superficie brute":186 nm = re.search(r"(\d[\d\s]*(?:[.,]\d+)?)\s*pi",187 dm.group(1))188 if nm:189 area_sqft = float(190 nm.group(1).replace(" ", "").replace(",", "."))191 extra = re.search(r"Avec boudoir|Avec bureau", text)192 amenities = [extra.group(0)] if extra else []193 tm = re.search(r"Superficie terrasse", text)194 if tm:195 amenities.append("Terrasse")196197 # étage structuré (segment /etage-N/ de l'URL)198 details: dict = {"contact": dict(CONTACT)}199 em = re.search(r"/etage-(\d+)/", full_url)200 if em:201 details["floor"] = int(em.group(1))202203 imgs = re.findall(204 r'(?:src|href)="((?:https?://[^"]+|/)?uploads/[^"]+'205 r'\.(?:jpg|jpeg|png|webp))"', html, re.I)206 images = []207 for u in dict.fromkeys(imgs):208 if not u.startswith("http"):209 u = BASE + ("/" + u.lstrip("/"))210 images.append(u)211212 listings.append(Listing(213 source=self.source_id,214 external_id=f"phase-{phase}-unite-{unit_no}",215 url=full_url,216 title=f"Quartier les Éléments — Phase {phase}, "217 f"unité {unit_no} ({unit_type})",218 address=ADDRESS,219 sector=SECTOR,220 city=infer_city(SECTOR),221 unit_type=unit_type,222 price=price,223 price_label=f"Prix : {prix_line}" if prix_line else "",224 availability=availability,225 area_sqft=area_sqft,226 description=" | ".join(desc_parts),227 amenities=amenities,228 details=details,229 images=images,230 ))231 except Exception:232 continue233234 return listings235