SPB Git

Repository Public

axia.py 9.0 KB 228 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Lou·Ka9# File             : louka/connectors/axia.py10# Module           : louka11# Repository       : https://git.spboucher.ai/lou-ka12# Created          : 2026-08-0613# Last Modified    : 2026-08-0814#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/axia.py : connecteur AXIA Appartements (axiaappartements.com)91#   Complexe locatif neuf à Lachine (Montréal), géré par Pur Immobilia.92#   Site vitrine WordPress/WPBakery une page : deux configurations93#   (2 chambres 4½ et 3 chambres 5½) avec superficie et prix94#   « à partir de » — 1 annonce par configuration.95# -----------------------------------------------------------------------------96from __future__ import annotations9798import re99100from bs4 import BeautifulSoup101102from ..schema import Listing, parse_price103from .base import BaseConnector104105BASE = "https://www.axiaappartements.com"106107ADDRESS = "200, boul. Saint-Joseph, Lachine (Québec) H8S 2L3"108109IMG_RE = re.compile(110    r"https://www\.axiaappartements\.com/wp-content/uploads/"111    r"[^\"\s\\]+?\.(?:jpg|jpeg|webp)", re.I)112113114class AxiaConnector(BaseConnector):115    source_id = "axia"116    request_delay = 0.6117118    def fetch(self) -> list[Listing]:119        listings: list[Listing] = []120        try:121            html = self.get(BASE + "/").text122        except Exception:123            return listings124        soup = BeautifulSoup(html, "html.parser")125126        # Photos du complexe (icônes/logos exclus)127        images = [u for u in dict.fromkeys(IMG_RE.findall(html))128                  if not re.search(r"icone|logo|favicon|fleche|-\d+x\d+\.",129                                   u, re.I)][:25]130131        # Description (meta + paragraphe « APPARTEMENTS » sur les unités)132        desc = ""133        og = soup.find("meta", attrs={"property": "og:description"}) or \134            soup.find("meta", attrs={"name": "description"})135        if og and og.get("content"):136            desc = og["content"].strip()137        for p in soup.find_all("p"):138            txt = re.sub(r"\s+", " ", p.get_text(" ", strip=True))139            if "électroménagers" in txt:      # descriptif des unités140                desc = (desc + " " + txt).strip()141                break142        desc = desc[:600]143        amenities = []144        for el in soup.select(".icon-label"):145            txt = re.sub(r"\s+", " ", el.get_text(" ", strip=True)).strip()146            if txt and txt not in amenities:147                amenities.append(txt)148149        # Contact (liens tel:/mailto: structurés — location résidentielle)150        contact: dict = {}151        tel = soup.select_one('a[href^="tel:"]')152        if tel:153            digits = re.sub(r"\D", "", tel.get("href", ""))[-10:]154            if len(digits) == 10:155                contact["phone"] = "-".join(156                    (digits[:3], digits[3:6], digits[6:]))157        mail = soup.select_one('a[href^="mailto:"]')158        if mail:159            contact["email"] = mail.get("href", "")[7:].split("?")[0]160161        # Disponibilité (texte du site) + promotion (dans la description,162        # pour ne pas fausser la date de disponibilité normalisée)163        page_text = re.sub(r"\s+", " ", soup.get_text(" ", strip=True))164        availability = "Disponible"165        if re.search(r"Maintenant disponible à la location", page_text, re.I):166            availability = "Maintenant disponible à la location"167        m = re.search(r"(\d\s*MOIS OFFERTS[^<*]{0,80})", page_text, re.I)168        if m:169            promo = "Promotion : " + re.sub(r"\s+", " ", m.group(1)).strip()170            desc = (desc + " — " + promo)[:600]171172        # Cartes de prix : « 2 chambres (4 ½) », superficie, « À partir de … $ »173        for card in soup.select(".price-card"):174            try:175                lst = self._parse_card(card, images, desc, amenities,176                                       availability, contact)177            except Exception:178                continue179            if lst:180                listings.append(lst)181        return listings182183    def _parse_card(self, card, images, desc, amenities,184                    availability, contact=None) -> Listing | None:185        head = card.get_text(" ", strip=True)          # « 2 chambres (4 ½) »186        m = re.search(r"(\d)\s*chambres?", head, re.I)187        mtype = re.search(r"\(\s*(\d)\s*(?:½|1/2)\s*\)", head)188        if not (m or mtype):189            return None190        if mtype:191            unit_type = f"{mtype.group(1)}½"192        else:193            n = int(m.group(1))194            unit_type = {0: "Studio", 1: "3½", 2: "4½", 3: "5½"}.get(195                n, f"{n} chambres")196197        # superficie et prix dans les blocs suivants du même conteneur198        container = card.parent199        sqft = price_label = ""200        if container:201            sq = container.select_one(".superficie")202            if sq:203                sqft = sq.get_text(" ", strip=True)204            mt = container.select_one(".montant")205            if mt:206                price_label = mt.get_text(" ", strip=True)207208        price = parse_price(price_label)209        n_ch = m.group(1) if m else {"4½": "2", "5½": "3"}.get(unit_type, "")210211        return Listing(212            source=self.source_id,213            external_id=f"axia-lachine-{unit_type.replace('½', '.5')}",214            url=BASE + "/#appartements",215            title=f"AXIA Appartements — {n_ch} chambres ({unit_type})",216            address=ADDRESS,217            sector="Lachine",218            city="Montréal",219            unit_type=unit_type,220            price=price,221            price_label=re.sub(r"\s+", " ", price_label).strip(),222            availability=availability,223            description=(f"{sqft}. {desc}" if sqft else desc)[:600],224            amenities=amenities[:15],225            details={"contact": dict(contact)} if contact else {},226            images=images,227        )228
Files main
Menu

Theme