SPB Git

Repository Public

leviu.py 9.5 KB 232 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/leviu.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/leviu.py : connecteur Le VIU / VIU2 (leviu.ca — Groupe Heafey)91#   Tours de condos locatifs du centre-ville de Gatineau (199, rue Laurier,92#   secteur Hull). Le site vitrine leviu.ca renvoie « Voir les condos à93#   louer » vers le portail Proprio Expert de Magex Technologies :94#     https://peweb.magextechnologies.com/RentalListings/Lsae1/Groupe-Heafey95#   Page ASP.NET WebForms ENTIÈREMENT rendue serveur : une carte par unité96#   disponible (« VIU2 Opérations Inc. — n condominiums à louer ») avec prix97#   (« 2 045,00 $ / mois »), adresse complète, taille (« 3 ½ (6 Étages,98#   890,00 pi²) »), animaux, code d'unité + note, date « Disponible: … » et99#   photo (ImageDownloadHandler). La navigation de fiche est un __doPostBack100#   sans URL propre : l'URL d'annonce pointe sur le portail avec un fragment.101#   external_id = adresse en slug (aucun identifiant public stable exposé).102#   NB : distinct du connecteur heafey (We 2/We 3/Loggia via Resimo, qui ne103#   publie pas les unités du VIU) — aucun doublon entre les deux sources.104# -----------------------------------------------------------------------------105from __future__ import annotations106107import re108109from bs4 import BeautifulSoup110111from ..schema import Listing, normalize_unit_type, parse_area_sqft, strip_accents112from .base import BaseConnector113114PORTAL_BASE = "https://peweb.magextechnologies.com"115LIST_URL = f"{PORTAL_BASE}/RentalListings/Lsae1/Groupe-Heafey"116SITE = "https://www.leviu.ca"117118119def _slug(text: str) -> str:120    s = strip_accents(text.lower())121    s = re.sub(r"[^a-z0-9]+", "-", s).strip("-")122    return s123124125class LeViuConnector(BaseConnector):126    source_id = "leviu"127    request_delay = 1.0128129    def fetch(self) -> list[Listing]:130        soup = BeautifulSoup(self.get(LIST_URL).text, "html.parser")131        listings: dict[str, Listing] = {}132        for card in soup.select("div[id*='ctlRentalListings_lView_divItem_']"):133            try:134                self._parse_card(card, listings)135            except Exception:136                continue137        return list(listings.values())138139    def _parse_card(self, card, listings: dict[str, Listing]) -> None:140        addr_el = card.select_one("span[id*='_ctlAddress_'][id*='_lLine1_']")141        if not addr_el:142            return143        # « 199 rue Laurier Unité 602, Gatineau (Québec) »144        full_addr = re.sub(r"\s+", " ", addr_el.get_text(" ", strip=True)).strip()145        if not full_addr:146            return147        m = re.match(r"^(.*?),\s*([^,()]+?)\s*\(([^)]+)\)\s*$", full_addr)148        street, city, province = (m.groups() if m else (full_addr, "", ""))149        if province and "qu" not in strip_accents(province.lower()):150            return                      # portail multi-provinces : QC seulement151152        ext_id = _slug(street or full_addr)153        if not ext_id or ext_id in listings:154            return155156        price_el = card.select_one("span[id*='_lPrice_']")157        price_label = re.sub(r"\s+", " ", price_el.get_text(" ", strip=True)) \158            if price_el else ""159160        # « 3 ½ (6 Étages, 890,00 pi²) »161        rooms_el = card.select_one("span[id*='_lRooms_']")162        rooms_txt = re.sub(r"\s+", " ", rooms_el.get_text(" ", strip=True)) \163            if rooms_el else ""164        unit_type = ""165        m = re.match(r"^\s*(\d+\s*½|Studio|Loft)", rooms_txt)166        if m:167            unit_type = normalize_unit_type(m.group(1))168        area_sqft = parse_area_sqft(rooms_txt)169        details: dict = {}170        m = re.search(r"(\d+)\s*Étages?", rooms_txt)171        if m:172            details["building_floors"] = int(m.group(1))173174        # animaux : « Oui » / « Non », avec note éventuelle en textNote175        # (« Sous certaines conditions, animaux tolérés » -> conditions)176        pets = None177        pets_note = ""178        anim_el = card.select_one("span[id*='_lAnimals_']")179        if anim_el:180            note_el = anim_el.select_one("span.textNote")181            if note_el:182                pets_note = re.sub(r"\s+", " ", note_el.get_text(" ", strip=True))183            k = strip_accents(anim_el.get_text(" ", strip=True).lower())184            if k.startswith("oui"):185                pets = "conditions" if re.search(r"condition", k) else "oui"186            elif k.startswith("non"):187                pets = "non"188        if pets_note:189            details["pets_note"] = pets_note190191        desc_el = card.select_one("span[id*='_lDescription_']")192        description = ""193        if desc_el:194            description = re.sub(r"[ \t]+", " ",195                                 desc_el.get_text("\n", strip=True)).strip()[:2500]196            m = re.match(r"^([A-Z]{1,3}-\d+[^\n]*)", description)197            if m:198                details["unit_code"] = m.group(1).strip()199        # « Sous certaines conditions, animaux tolérés » -> conditions200        if pets == "oui" and re.search(r"condition", description, re.I):201            pets = "conditions"202203        avail_el = card.select_one("span[id*='_lAvailable_']")204        availability = re.sub(r"\s+", " ", avail_el.get_text(" ", strip=True)) \205            if avail_el else ""206207        images: list[str] = []208        for im in card.select("img[id*='_img_'][src]"):209            u = im["src"]210            if not u.startswith("http"):211                u = PORTAL_BASE + u212            if u not in images:213                images.append(u)214215        listings[ext_id] = Listing(216            source=self.source_id,217            external_id=ext_id,218            url=f"{LIST_URL}#{ext_id}",219            title=street,220            address=f"{street}, {city}" if city else street,221            sector="Hull" if re.search(r"rue Laurier", street, re.I) else "",222            city=city or "Gatineau",223            unit_type=unit_type,224            price_label=price_label,225            availability=availability,226            area_sqft=area_sqft,227            pets=pets,228            description=description,229            details=details,230            images=images,231        )232
Files main
Menu

Theme