SPB Git

Repository Public

luxuor.py 9.7 KB 244 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/luxuor.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/luxuor.py : connecteur Les Immeubles Luxuor91#   (lesimmeublesluxuor.com — ville de Saguenay). Condos locatifs neufs haut de92#   gamme rue des Golfeurs (arrondissement Chicoutimi, projets « 42 logements »93#   et « 16 logements »), plex « Quadrex » et résidence étudiante « La94#   Fabrique » (3821 rue de la Fabrique, Jonquière). Site Wix rendu serveur,95#   4 pages projet FIXES sans fiches d'unités ni prix ni disponibilités96#   (visites par formulaire) -> 1 annonce « catalogue » par projet, granularité97#   PROJET (précédent girs/immeubles_guillot/alias_appartements), price=None,98#   rien d'inventé. Texte extrait des blocs Wix `div[data-testid=99#   "richTextElement"]` du <main> (les menus, légendes de galerie et pieds de100#   page sont hors de ces blocs) : lignes courtes = pictogrammes de commodités101#   (« Ascenseur », « Gym »…), lignes longues = description. Types multiples102#   (3½-5½) cités en prose -> unit_type vide, la description fait foi.103#   external_id stable : slug de page. robots.txt Wix standard (ouvert).104# -----------------------------------------------------------------------------105from __future__ import annotations106107import re108109from bs4 import BeautifulSoup110111from ..schema import Listing112from .base import BaseConnector113114BASE = "https://www.lesimmeublesluxuor.com"115116# (slug, secteur affiché par la page, extraire les pictogrammes ?)117PAGES = [118    ("42logements", "Chicoutimi", True),119    ("16logements", "Chicoutimi", True),120    ("quadrex", "", True),121    ("lafabrique", "Jonquière", False),   # sections Chambre 1/Cuisine… : prose122]123124_ADDR_RE = re.compile(r"\d{2,5},?\s+rue de la Fabrique[^,]*,\s*Jonquière"125                      r"(?:,\s*QC(?:\s+\w\d\w\s*\d\w\d)?)?", re.I)126_GOLFEURS_RE = re.compile(r"rue des Golfeurs", re.I)127_TYPE_RE = re.compile(r"([1-6])\s*(?:½|1/2)")128# lignes courtes à ne PAS traiter comme commodités (titres, CTA…)129_SKIP_LINE = re.compile(130    r"(?i)^(photos?\s*&\s*plans?|un projet qui|réservez|laissez|découvrez|"131    r"venez|nos logements|type de logement|contact)", re.I)132133134def _full_size(url: str) -> str:135    """URL wixstatic redimensionnée -> média pleine taille (coupe au /v1/)."""136    return url.split("/v1/")[0] if "/v1/" in url else url137138139class LuxuorConnector(BaseConnector):140    source_id = "luxuor"141    request_delay = 0.6142    max_images = 10143144    def fetch(self) -> list[Listing]:145        listings: list[Listing] = []146        for slug, sector, with_amenities in PAGES:147            try:148                lst = self._parse_page(slug, sector, with_amenities)149            except Exception:150                continue151            if lst is not None:152                listings.append(lst)153        return listings154155    # -- page projet Wix -----------------------------------------------------------156    def _parse_page(self, slug: str, sector: str,157                    with_amenities: bool) -> Listing | None:158        url = f"{BASE}/{slug}"159        soup = BeautifulSoup(self.get(url).text, "html.parser")160        main = soup.select_one("main") or soup.body161        if main is None:162            return None163164        blocks = main.select('div[data-testid="richTextElement"]')165        if not blocks:166            return None167168        # lignes de texte au niveau des <p> (une commodité Wix par <p>)169        lines: list[str] = []170        for blk in blocks:171            ps = blk.select("p")172            if ps:173                lines += [re.sub(r"\s+", " ", p.get_text(" ", strip=True))174                          .replace("", "").strip() for p in ps]175            else:176                lines.append(re.sub(r"\s+", " ", blk.get_text(" ", strip=True))177                             .replace("", "").strip())178        lines = [t for t in lines if t]179        if not lines:180            return None181182        # titre = premier(s) bloc(s) court(s) (« 42 LOGEMENTS », « Résidence183        # étudiante / LA FABRIQUE »)184        head = re.sub(r"\s+", " ", blocks[0].get_text(" ", strip=True)185                      ).replace("", "").strip()186        if slug == "lafabrique" and len(blocks) > 1:187            head = f"{head} {blocks[1].get_text(' ', strip=True)}".strip()188        name = head.title() if head.isupper() else head189190        paras: list[str] = []191        amenities: list[str] = []192        for t in lines:193            if t == head or _SKIP_LINE.match(t):194                continue195            if len(t) >= 45:196                if len(paras) < 10:197                    paras.append(t)198            elif (with_amenities and 3 <= len(t) < 45199                    and not t.endswith((".", "!", "?", ":"))200                    and t not in amenities):201                amenities.append(t)202        description = "\n".join(paras)[:1600]203        if not description and not amenities:204            return None                     # page méconnaissable205206        text = " ".join(lines)207        m_addr = _ADDR_RE.search(text)208        if m_addr:209            address = m_addr.group(0)210        elif _GOLFEURS_RE.search(text):211            address = "Rue des Golfeurs, Chicoutimi"212        else:213            address = ""214215        # type d'unités : seulement si UN seul type est cité en prose216        types = sorted(set(_TYPE_RE.findall(text)))217        unit_type = f"{types[0]}½" if len(types) == 1 else ""218219        images: list[str] = []220        for img in main.select("img[src]"):221            u = _full_size(img["src"])222            if (u.startswith("https://static.wixstatic.com")223                    and not u.lower().endswith(".svg") and u not in images):224                images.append(u)225                if len(images) >= self.max_images:226                    break227228        return Listing(229            source=self.source_id,230            external_id=slug,231            url=url,232            title=f"Les Immeubles Luxuor — {name}",233            address=address,234            sector=sector,235            city="Saguenay",       # tous les projets du site sont à Ville Saguenay236            unit_type=unit_type,237            price=None,             # aucun loyer publié sur le site238            price_label="",239            availability="",        # visites par formulaire : rien d'inventé240            description=description,241            amenities=amenities[:30],242            images=images,243        )244
Files main
Menu

Theme