Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/atlas_immo.py10# Module : louka11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0913# Last Modified : 2026-08-0914#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/atlas_immo.py : connecteur Atlas société immobilière91# (atlasimmo.ca — Beauce : Saint-Georges, Saint-Victor, Notre-Dame-des-Pins,92# ~50-100 logements 2½–6½). CMS custom « webchef », pages .php statiques93# servies en HTTP (pas de TLS). Page /logements-a-louer-en-beauce.php : toutes94# les unités disponibles sont rendues serveur (cartes `div.resultat` — nom95# d'immeuble, rue + ville, description « 4X 4 et demi moderne », drapeaux96# Disponible/Chauffé/Éclairé avec icônes ok/cancel, photo) ; le filtre97# ville/grandeur/prix est purement client (JS). Quand aucun logement n'est98# libre, seule la mention « Aucun appartement n'est disponible… » s'affiche99# et le connecteur retourne [] — situation normale (parc beauceron plein).100# Prix jamais affiché sur les cartes -> None (rien d'inventé) ; granularité101# immeuble assumée (précédent immeubles_guillot). Les fiches102# /logement-a-louer/<id>-<slug>.php existent mais leur structure n'a jamais103# été observée (aucune archive) : pas d'appel détail pour l'instant.104# robots.txt : Disallow répertoires internes (/webchef, /inc…) seulement.105# -----------------------------------------------------------------------------106from __future__ import annotations107108import re109110from bs4 import BeautifulSoup111112from ..schema import Listing, normalize_unit_type113from .base import BaseConnector114115BASE = "http://www.atlasimmo.ca"116LIST_URL = f"{BASE}/logements-a-louer-en-beauce.php"117118# type d'unité dans la description d'immeuble (« 4X 4 et demi moderne »)119_TYPE_RE = re.compile(r"(\d)\s*(?:½|1/2|et\s+demi)", re.I)120121122class AtlasImmoConnector(BaseConnector):123 source_id = "atlas_immo"124 request_delay = 0.6125126 def fetch(self) -> list[Listing]:127 html = self.get(LIST_URL).text128 soup = BeautifulSoup(html, "html.parser")129130 listings: dict[str, Listing] = {}131 for card in soup.select("div.resultat"):132 try:133 self._parse_card(card, listings)134 except Exception:135 continue136 return list(listings.values())137138 # -- carte (div.resultat, id bloc-<n>) -----------------------------------------139 def _parse_card(self, card, listings: dict[str, Listing]) -> None:140 link = card.select_one('a[href*="/logement-a-louer/"]')141 if not link:142 return143 url = link["href"]144 if url.startswith("/"):145 url = BASE + url146 m = re.search(r"/logement-a-louer/([^/?#]+?)(?:\.php)?$", url)147 if not m:148 return149 ext_id = m.group(1)150 if not ext_id or ext_id in listings:151 return152153 title_el = card.select_one("h2")154 title = title_el.get_text(strip=True) if title_el else ""155156 # adresse : <li>Rue Ambroise<br><strong>Saint-Victor</strong>, ---</li>157 address, city = "", ""158 li = card.select_one(".description ul li")159 if li:160 strong = li.select_one("strong")161 city = strong.get_text(strip=True) if strong else ""162 street = li.get_text("\n", strip=True).split("\n")[0].strip()163 street = street.rstrip(",")164 address = f"{street}, {city}".strip(", ") if city else street165166 # description libre de l'immeuble (« 4X 4 et demi moderne »)167 desc_el = card.select_one(".description p:not(.aligneDroit)")168 description = desc_el.get_text(" ", strip=True) if desc_el else ""169170 m_type = _TYPE_RE.search(description)171 unit_type = normalize_unit_type(f"{m_type.group(1)} ½") if m_type else ""172173 # drapeaux : <span><i class="icon-ok"/> Disponible</span> — icon-cancel = non174 availability = ""175 amenities: list[str] = []176 for span in card.select(".options span"):177 label = span.get_text(" ", strip=True)178 icon = span.select_one("i")179 ok = bool(icon and "icon-ok" in (icon.get("class") or []))180 if re.search(r"disponible", label, re.I):181 if ok:182 availability = label183 elif ok and label:184 amenities.append(label)185186 images: list[str] = []187 img = card.select_one("img[src]")188 if img:189 u = img["src"]190 if u.startswith("/"):191 u = BASE + u192 if u.startswith("http"):193 images.append(u)194195 listings[ext_id] = Listing(196 source=self.source_id,197 external_id=ext_id,198 url=url,199 title=title,200 address=address,201 city=city,202 unit_type=unit_type,203 price=None, # jamais affiché sur les cartes204 price_label="",205 availability=availability,206 description=description,207 amenities=amenities,208 images=images,209 )210