SPB Git

Repository Public

helio.py 8.6 KB 214 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/helio.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/helio.py : connecteur Entreprises Hélio (entrepriseshelio.ca)91#   Trois immeubles en Montérégie : 2417 Montarville et 335-345 Place du92#   Collège à Longueuil, 1065-1075 boul. de Palerme à La Prairie.93#   WordPress + Divi rendu serveur : la page /a-louer/ liste une section par94#   typologie (h3 « 3 1/2, Place du Collège », « 4 1/2, Palerme »…) suivie95#   d'un encadré « Disponibilité : <valeur> » et des caractéristiques (li).96#   Une typologie marquée « COMPLET » n'est PAS ingérée : seules les sections97#   avec une vraie disponibilité (date ou « disponible ») deviennent des98#   annonces. Il est donc normal que ce connecteur retourne 0 annonce quand99#   tout le parc est loué (état observé au 2026-08-25).100# -----------------------------------------------------------------------------101from __future__ import annotations102103import re104105from bs4 import BeautifulSoup106107from ..schema import Listing, normalize_unit_type108from .base import BaseConnector109110BASE = "https://www.entrepriseshelio.ca"111LIST_URL = f"{BASE}/a-louer/"112113# immeuble (mot-clé du titre de section) -> adresse et ville114BUILDINGS = {115    "montarville": ("2417, rue de Montarville, Longueuil", "Longueuil"),116    "college": ("335-345, place du Collège, Longueuil", "Longueuil"),117    "palerme": ("1065-1075, boulevard de Palerme, La Prairie", "La Prairie"),118}119120# titre de section d'unité : « 3 1/2, Place du Collège – Demi Sous-Sol »121TITLE_RE = re.compile(r"^(\d\s*1/2)\s*,\s*(.+)$")122COMPLET_RE = re.compile(r"\bCOMPLET\b", re.I)123IMG_RE = re.compile(124    r"https://www\.entrepriseshelio\.ca/wp-content/uploads/"125    r"[^\"\s\\']+\.(?:jpe?g|png|webp)", re.I)126SKIP_IMG_RE = re.compile(r"logo|icon|favicon|-\d{2,3}x\d{2,3}\.", re.I)127128129def _slug(text: str) -> str:130    from ..schema import strip_accents131    s = strip_accents(text.lower())132    return re.sub(r"-{2,}", "-", re.sub(r"[^a-z0-9]+", "-", s)).strip("-")133134135class HelioConnector(BaseConnector):136    source_id = "helio"137    request_delay = 0.6138139    def fetch(self) -> list[Listing]:140        listings: list[Listing] = []141        try:142            html = self.get(LIST_URL).text143        except Exception:144            return listings145        soup = BeautifulSoup(html, "html.parser")146147        for h3 in soup.find_all("h3"):148            try:149                if "et_pb_gallery_title" in (h3.get("class") or []):150                    continue                      # légendes de galerie Divi151                title = h3.get_text(" ", strip=True)152                m = TITLE_RE.match(title)153                if not m:154                    continue155                unit_type = normalize_unit_type(m.group(1))156                where = m.group(2).strip()157158                # section Divi englobante (colonne/row) : dispo + listes159                section = h3160                for _ in range(8):161                    section = section.parent162                    if section is None:163                        break164                    cls = " ".join(section.get("class") or [])165                    txt = section.get_text(" ", strip=True)166                    if "et_pb_row" in cls and "Disponibilité" in txt:167                        break168                if section is None:169                    continue170                stext = section.get_text(" | ", strip=True)171172                # disponibilité : valeur qui suit « Disponibilité : »173                availability = ""174                m2 = re.search(r"Disponibilité\s*\|?\s*:\s*\|?\s*([^|]+)",175                               stext)176                if m2:177                    availability = m2.group(1).strip()178                if COMPLET_RE.search(availability):179                    continue                      # typologie complète : exclue180                if not availability:181                    continue                      # rien d'affiché : prudence182183                # immeuble -> adresse/ville184                key = _slug(where)185                address, city = "", ""186                for kw, (addr, ct) in BUILDINGS.items():187                    if kw in key:188                        address, city = addr, ct189                        break190191                amenities = [li.get_text(" ", strip=True)192                             for li in section.find_all("li")193                             if li.get_text(strip=True)194                             and "photos sont représentatives"195                             not in li.get_text()][:20]196                images = [u for u in dict.fromkeys(IMG_RE.findall(str(section)))197                          if not SKIP_IMG_RE.search(u)][:15]198199                listings.append(Listing(200                    source=self.source_id,201                    external_id=f"{unit_type.replace('½', '.5')}-{key}",202                    url=LIST_URL,203                    title=title,204                    address=address,205                    city=city,206                    unit_type=unit_type,207                    availability=availability,208                    amenities=amenities,209                    images=images,210                ))211            except Exception:212                continue213        return listings214
Files main
Menu

Theme