SPB Git

Repository Public

st_charles_granby.py 6.9 KB 172 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/st_charles_granby.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/st_charles_granby.py : connecteur Le St-Charles (stcharlesgranby.com)91#   Condos locatifs modernes au 41, rue Saint-Charles Nord à Granby (studios,92#   3½, 4½, 5½). WordPress/Elementor rendu serveur : la page d'accueil affiche93#   une carte par typologie (« 3 1/2 / À partir de 900$ / mois* »).94#   Granularité : typologie (pas d'unités individuelles publiées).95# -----------------------------------------------------------------------------96from __future__ import annotations9798import re99100from bs4 import BeautifulSoup101102from .base import BaseConnector103from ..schema import Listing, normalize_unit_type104105BASE = "https://www.stcharlesgranby.com"106107ADDRESS = "41, rue Saint-Charles Nord, Granby"108CITY = "Granby"109110TYPE_RE = re.compile(r"^(studio|\d\s*(?:1/2|½))$", re.I)111PRICE_RE = re.compile(r"À\s*partir\s*de\s*(\d[\d\s  ]{2,6})\$\s*/\s*mois",112                      re.I)113IMG_RE = re.compile(r'https://www\.stcharlesgranby\.com/wp-content/uploads/'114                    r'[^"\s\\)]+\.(?:jpe?g|png|webp)', re.I)115116117class StCharlesGranbyConnector(BaseConnector):118    source_id = "st_charles_granby"119    request_delay = 0.6120121    def fetch(self) -> list[Listing]:122        listings: list[Listing] = []123        try:124            html = self.get(BASE + "/").text125        except Exception:126            return listings127        soup = BeautifulSoup(html, "html.parser")128        lines = soup.get_text("\n", strip=True).split("\n")129130        images = [u for u in dict.fromkeys(IMG_RE.findall(html))131                  if not re.search(r"logo|icon|favicon|plan|"132                                   r"-\d{2,4}x\d{2,4}\.", u, re.I)][:15]133134        # cartes « Studio / À partir de 900$ / mois* » (le menu répète les135        # typologies sans prix : on n'accepte que type suivi d'un prix)136        for i, line in enumerate(lines):137            raw = line.strip()138            if not TYPE_RE.match(raw):139                continue140            nxt = lines[i + 1].strip() if i + 1 < len(lines) else ""141            if TYPE_RE.match(nxt):142                continue          # menu de navigation (types à la suite)143            m = PRICE_RE.search(nxt)144            if not m:145                continue146            unit_type = ("Studio" if raw.lower() == "studio"147                         else normalize_unit_type(raw))148            try:149                price = float(m.group(1).replace(" ", "").replace(" ", ""))150            except ValueError:151                continue152            ext_id = ("granby-studio" if unit_type == "Studio" else153                      f"granby-{unit_type.replace('½', '.5')}")154            if any(l.external_id == ext_id for l in listings):155                continue156            listings.append(Listing(157                source=self.source_id,158                external_id=ext_id,159                url=BASE + "/",160                title=f"{unit_type} — Le St-Charles",161                address=ADDRESS,162                city=CITY,163                unit_type=unit_type,164                price=price,165                price_label=f"À partir de {m.group(1).strip()}$ / mois",166                description="Condos locatifs modernes, lumineux et bien "167                            "pensés au cœur de Granby (studios, 3½, 4½ "168                            "et 5½), à distance de marche des services.",169                images=images,170            ))171        return listings172
Files main
Menu

Theme