SPB Git

Repository Public

port_de_mer.py 7.0 KB 183 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/port_de_mer.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/port_de_mer.py : connecteur Port de Mer (portdemer.ca)91#   Complexe locatif unique de 389 unités au 99-101 Place Charles-LeMoyne,92#   Longueuil — directement en face du métro Longueuil. Site une-page93#   (CMS Prog Expert) rendu serveur : description, caractéristiques,94#   fourchette de prix « À partir de : 1515 $ - 2040 $ ». Aucun inventaire95#   par unité publié (sitemap-Room vide) → une annonce par immeuble,96#   comme brochu.py.97# -----------------------------------------------------------------------------98from __future__ import annotations99100import re101102from bs4 import BeautifulSoup103104from ..schema import Listing105from .base import BaseConnector106107BASE = "https://portdemer.ca"108PAGE_URL = f"{BASE}/fr/accueil"109110ADDRESS = "99-101, Place Charles-LeMoyne, Longueuil"111PRICE_RE = re.compile(r"[ÀA]\s*partir\s*de\s*:?\s*([\d\s ,]+)\s*\$"112                      r"(?:\s*[-–]\s*([\d\s ,]+)\s*\$)?", re.I)113IMG_RE = re.compile(r"(?:https?:)?//portdemer\.ca/mod/file/"114                    r"(?:Block|SubBlock)Image/[^\"'()\s]+\.(?:jpe?g|png|webp)"115                    r"[^\"'()\s]*", re.I)116117118def _num(txt: str) -> float | None:119    try:120        return float(txt.replace(" ", "").replace(" ", "").replace(",", ""))121    except (AttributeError, ValueError):122        return None123124125class PortDeMerConnector(BaseConnector):126    source_id = "port_de_mer"127    request_delay = 0.6128129    def fetch(self) -> list[Listing]:130        try:131            html = self.get(PAGE_URL).text132        except Exception:133            return []134        soup = BeautifulSoup(html, "html.parser")135        text = soup.get_text("\n", strip=True)136137        price = None138        price_label = ""139        m = PRICE_RE.search(text)140        if m:141            price = _num(m.group(1))142            price_label = re.sub(r"\s+", " ", m.group(0)).strip()143144        # description : paragraphes substantiels de la section d'intro145        paras = [p.get_text(" ", strip=True) for p in soup.find_all("p")146                 if len(p.get_text(strip=True)) > 80]147        description = re.sub(r"\s+", " ", " ".join(paras[:4])).strip()[:1200]148149        # caractéristiques : les <li> des blocs sw-text (listes à puces)150        amenities: list[str] = []151        for li in soup.select("div.sw-text li"):152            t = re.sub(r"\s+", " ", li.get_text(" ", strip=True))153            if 0 < len(t) <= 60 and t not in amenities:154                amenities.append(t)155156        images = [("https:" + u if u.startswith("//") else u).split("?")[0]157                  for u in dict.fromkeys(IMG_RE.findall(html))][:20]158159        contact: dict = {}160        m = re.search(r'href="mailto:([^"?]+)"', html)161        if m:162            contact["email"] = m.group(1).strip().lower()163        m = re.search(r'href="tel:\+?1?(\d{3})(\d{3})(\d{4})"', html)164        if m:165            contact["phone"] = f"{m.group(1)}-{m.group(2)}-{m.group(3)}"166167        return [Listing(168            source=self.source_id,169            external_id="port-de-mer-longueuil",170            url=PAGE_URL,171            title="Port de Mer — appartements face au métro Longueuil",172            address=ADDRESS,173            city="Longueuil",174            price=price,175            price_label=price_label,176            availability="Informations et locations : "177                         "communiquer avec l'immeuble",178            description=description,179            amenities=amenities[:20],180            details={"contact": contact} if contact else {},181            images=images,182        )]183
Files main
Menu

Theme