SPB Git

Repository Public

probloc.py 9.9 KB 246 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/probloc.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/probloc.py : connecteur Probloc CL inc. (probloccl.com)91#   Gestionnaire immobilier de Bécancour (Centre-du-Québec) — parc de plex et92#   d'immeubles répartis dans les secteurs Gentilly / Croix-du-Sud / centre.93#   Le site vitrine probloccl.com (Next.js) renvoie « Logements à louer » vers94#   le portail Proprio Expert de Magex Technologies :95#     https://peweb.magextechnologies.com/RentalListings/Ffllf1/Probloc-Cl-Inc96#   Même plateforme ASP.NET WebForms rendue serveur que leviu.py : une carte97#   par unité disponible avec prix (« 1 150,00 $ / mois »), adresse complète,98#   taille (« 4 ½ (2 Chambres, 1 200,00 pi²) » ou « 1 Chambre » pour les99#   chambres), animaux, description, date « Disponible: … » et photo.100#   Pas d'URL de fiche propre (__doPostBack) : l'URL d'annonce pointe sur le101#   portail avec un fragment. external_id = adresse en slug (aucun identifiant102#   public stable exposé — même convention que leviu).103# -----------------------------------------------------------------------------104from __future__ import annotations105106import re107108from bs4 import BeautifulSoup109110from ..schema import Listing, normalize_unit_type, parse_area_sqft, strip_accents111from .base import BaseConnector112113PORTAL_BASE = "https://peweb.magextechnologies.com"114LIST_URL = f"{PORTAL_BASE}/RentalListings/Ffllf1/Probloc-Cl-Inc"115SITE = "https://probloccl.com"116117UNIT_RE = re.compile(r"^\s*(\d+\s*½|Studio|Loft)")118CHAMBRE_RE = re.compile(r"^\s*\d+\s*Chambres?\s*(?:\(|$)", re.I)119BEDROOMS_RE = re.compile(r"(\d+)\s*Chambres?", re.I)120FLOORS_RE = re.compile(r"(\d+)\s*Étages?", re.I)121122123def _slug(text: str) -> str:124    s = strip_accents(text.lower())125    s = re.sub(r"[^a-z0-9]+", "-", s).strip("-")126    return s127128129class ProblocConnector(BaseConnector):130    source_id = "probloc"131    request_delay = 1.0132133    def fetch(self) -> list[Listing]:134        soup = BeautifulSoup(self.get(LIST_URL).text, "html.parser")135        listings: dict[str, Listing] = {}136        for card in soup.select("div[id*='ctlRentalListings_lView_divItem_']"):137            try:138                self._parse_card(card, listings)139            except Exception:140                continue141        return list(listings.values())142143    def _parse_card(self, card, listings: dict[str, Listing]) -> None:144        addr_el = card.select_one("span[id*='_ctlAddress_'][id*='_lLine1_']")145        if not addr_el:146            return147        # « 1842 Av. de la Croix du Sud, Bécancour (Québec) »148        full_addr = re.sub(r"\s+", " ", addr_el.get_text(" ", strip=True)).strip()149        if not full_addr:150            return151        m = re.match(r"^(.*?),\s*([^,()]+?)\s*\(([^)]+)\)\s*$", full_addr)152        street, city, province = (m.groups() if m else (full_addr, "", ""))153        if province and "qu" not in strip_accents(province.lower()):154            return                      # portail multi-provinces : QC seulement155156        ext_id = _slug(street or full_addr)157        if not ext_id or ext_id in listings:158            return159160        price_el = card.select_one("span[id*='_lPrice_']")161        price_label = re.sub(r"\s+", " ", price_el.get_text(" ", strip=True)) \162            if price_el else ""163164        # « 4 ½ (2 Chambres, 2 Étages, 1 200,00 pi²) » ou « 1 Chambre »165        rooms_el = card.select_one("span[id*='_lRooms_']")166        rooms_txt = re.sub(r"\s+", " ", rooms_el.get_text(" ", strip=True)) \167            if rooms_el else ""168        unit_type = ""169        bedrooms: float | None = None170        m = UNIT_RE.match(rooms_txt)171        if m:172            unit_type = normalize_unit_type(m.group(1))173            m2 = BEDROOMS_RE.search(rooms_txt)174            if m2:175                bedrooms = float(m2.group(1))176        elif CHAMBRE_RE.match(rooms_txt):177            unit_type = "Chambre"       # chambres à louer (550-600 $)178        area_sqft = parse_area_sqft(rooms_txt)179        details: dict = {}180        m = FLOORS_RE.search(rooms_txt)181        if m:182            details["building_floors"] = int(m.group(1))183184        # animaux : « Oui » / « Non », avec note éventuelle en textNote185        pets = None186        pets_note = ""187        anim_el = card.select_one("span[id*='_lAnimals_']")188        if anim_el:189            note_el = anim_el.select_one("span.textNote")190            if note_el:191                pets_note = re.sub(r"\s+", " ", note_el.get_text(" ", strip=True))192            k = strip_accents(anim_el.get_text(" ", strip=True).lower())193            if k.startswith("oui"):194                pets = "conditions" if re.search(r"condition", k) else "oui"195            elif k.startswith("non"):196                pets = "non"197        if pets_note:198            details["pets_note"] = pets_note199200        desc_el = card.select_one("span[id*='_lDescription_']")201        description = ""202        if desc_el:203            description = re.sub(r"[ \t]+", " ",204                                 desc_el.get_text("\n", strip=True)).strip()[:2500]205            m = re.match(r"^([A-Z]{1,3}-\d+[^\n]*)", description)206            if m:207                details["unit_code"] = m.group(1).strip()208        if pets == "oui" and re.search(r"condition", description, re.I):209            pets = "conditions"210211        avail_el = card.select_one("span[id*='_lAvailable_']")212        availability = re.sub(r"\s+", " ", avail_el.get_text(" ", strip=True)) \213            if avail_el else ""214215        images: list[str] = []216        for im in card.select("img[id*='_img_'][src]"):217            u = im["src"]218            if not u.startswith("http"):219                u = PORTAL_BASE + u220            if u not in images:221                images.append(u)222223        # secteur : la Croix-du-Sud / Gentilly sont des repères connus du parc224        sector = ""225        if re.search(r"croix[- ]du[- ]s", strip_accents(street.lower())):226            sector = "Gentilly"227228        listings[ext_id] = Listing(229            source=self.source_id,230            external_id=ext_id,231            url=f"{LIST_URL}#{ext_id}",232            title=street,233            address=f"{street}, {city}" if city else street,234            sector=sector,235            city=city or "Bécancour",236            unit_type=unit_type,237            bedrooms=bedrooms,238            price_label=price_label,239            availability=availability,240            area_sqft=area_sqft,241            pets=pets,242            description=description,243            details=details,244            images=images,245        )246
Files main
Menu

Theme