Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/miner.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/miner.py : connecteur Le Miner (leminer.ca)91# Unités locatives neuves au 354, rue Principale à Granby (reconversion du92# site Miner). Webflow statique rendu serveur : la page /unites affiche93# trois cartes de typologie (« Unités d'une chambre / à partir de94# 1 470 $/mois »). Granularité : typologie (pas d'unités individuelles).95# -----------------------------------------------------------------------------96from __future__ import annotations9798import re99100from bs4 import BeautifulSoup101102from .base import BaseConnector103from ..schema import Listing104105BASE = "https://leminer.ca"106LIST_URL = f"{BASE}/unites"107108ADDRESS = "354, rue Principale, Granby"109CITY = "Granby"110111# « Unités d'une chambre » / « Unités de deux chambres avec deux salles de bain »112CARD_RE = re.compile(r"^Unités?\s+(?:d'une|de\s+(?:une|deux|trois))\s+chambres?"113 r"(?:\s+avec\s+(?:une|deux)\s+salles?\s+de\s+bain)?$", re.I)114PRICE_RE = re.compile(r"à\s*partir\s*de\s*([\d\s ]{4,9})\$\s*/\s*mois", re.I)115IMG_RE = re.compile(r'(?:src|href)="(images/[^"]+\.(?:jpe?g|png|webp))"', re.I)116117WORD_NUM = {"une": 1, "deux": 2, "trois": 3}118119120class MinerConnector(BaseConnector):121 source_id = "miner"122 request_delay = 0.6123124 def fetch(self) -> list[Listing]:125 listings: list[Listing] = []126 try:127 r = self.get(LIST_URL)128 r.encoding = "utf-8" # le serveur n'annonce pas le charset129 html = r.text130 except Exception:131 return listings132 soup = BeautifulSoup(html, "html.parser")133 lines = soup.get_text("\n", strip=True).split("\n")134135 images = [f"{BASE}/{u}" for u in dict.fromkeys(IMG_RE.findall(html))136 if not re.search(r"favicon|webclip|facebook|logo|icon|"137 r"vector", u, re.I)][:15]138139 for i, line in enumerate(lines):140 raw = line.strip()141 if not CARD_RE.match(raw):142 continue143 m = PRICE_RE.search(" ".join(lines[i + 1:i + 3]))144 if not m:145 continue146 try:147 price = float(m.group(1).replace(" ", "")148 .replace(" ", "").replace(" ", ""))149 except ValueError:150 continue151152 bedrooms = None153 mb = re.search(r"(?:d')?(une|deux|trois)\s+chambre", raw, re.I)154 if mb:155 bedrooms = WORD_NUM.get(mb.group(1).lower())156 bathrooms = None157 ms = re.search(r"avec\s+(une|deux)\s+salles?\s+de\s+bain", raw, re.I)158 if ms:159 bathrooms = WORD_NUM.get(ms.group(1).lower())160161 ext_id = f"granby-{bedrooms or 'x'}cc" + (162 f"-{bathrooms}sdb" if bathrooms else "")163 if any(l.external_id == ext_id for l in listings):164 continue165 listings.append(Listing(166 source=self.source_id,167 external_id=ext_id,168 url=LIST_URL,169 title=f"{raw} — Le Miner",170 address=ADDRESS,171 city=CITY,172 bedrooms=bedrooms,173 bathrooms=bathrooms,174 price=price,175 price_label=f"À partir de {m.group(1).strip()} $/mois",176 description="Unités locatives neuves du projet Le Miner à "177 "Granby : chambres spacieuses, espaces réfléchis "178 "et lumineux, au cœur du centre-ville.",179 images=images,180 ))181 return listings182