Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/symbio.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/symbio.py : connecteur Symbio (symbiohabitat.ca) — immeuble locatif91# de 219 unités (Développement FTG / Claridge) au 1475, rue Yves-Blais,92# Terrebonne (Lachenaie). La page /appartements/ embarque une application93# React « plans » (iframe wp-content/themes/hello-elementor/iframe) qui lit94# son inventaire dans une feuille Google Sheets PUBLIÉE EN CSV : colonnes95# Unit, Area (pi²), Type (n -> n½), Chambers, Bathrooms, Balcony (pi²),96# Price, Status (Available/Rented), PDF (plan). On découvre l'URL du CSV en97# suivant iframe -> main.<hash>.js (repli : URL relevée 2026-08-25).98# Granularité UNITÉ : prix, pi², chambres/sdb, plan PDF par unité.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import csv103import io104import re105106from ..schema import Listing107from .base import BaseConnector108109SITE = "https://symbiohabitat.ca"110PAGE_URL = f"{SITE}/appartements/"111APP_BASE = f"{SITE}/wp-content/themes/hello-elementor"112IFRAME_URL = f"{APP_BASE}/iframe?lang=fr"113114# URL du CSV publié (repli si la découverte via le JS de l'app casse)115FALLBACK_CSV = ("https://docs.google.com/spreadsheets/d/e/2PACX-1vSv4yfAI-E4opE"116 "tejmwNY74SEVrHTbxt34FpyUYiN_xKPHv_Swf2iqi-OzqTa3oMALF39YDLttP"117 "-WTI/pub?output=csv&gid=0")118119ADDRESS = "1475, rue Yves-Blais, Terrebonne"120BUILDING_AMENITIES = ["Gym", "Chalet urbain avec terrasse",121 "Bornes de recharge électrique", "Ascenseurs"]122123MAIN_JS_RE = re.compile(r'src="\./(static/js/main\.[0-9a-f]+\.js)"')124SHEET_RE = re.compile(125 r'https://docs\.google\.com/spreadsheets/d/e/[\w-]+/pub\?output=csv[^"\']*')126127128class SymbioConnector(BaseConnector):129 source_id = "symbio"130 request_delay = 0.8131132 # -- découverte de l'URL du CSV dans le bundle JS de l'app « plans » -------133 def _csv_url(self) -> str:134 try:135 html = self.get(IFRAME_URL).text136 m = MAIN_JS_RE.search(html)137 if m:138 js = self.get(f"{APP_BASE}/iframe/{m.group(1)}").text139 m2 = SHEET_RE.search(js)140 if m2:141 return m2.group(0).split("&date=")[0].rstrip("&")142 except Exception:143 pass144 return FALLBACK_CSV145146 def fetch(self) -> list[Listing]:147 listings: list[Listing] = []148 try:149 raw = self.get(self._csv_url()).text150 except Exception:151 return listings152 for row in csv.DictReader(io.StringIO(raw)):153 status = (row.get("Status") or "").strip().lower()154 unit = (row.get("Unit") or "").strip()155 if status != "available" or not unit:156 continue157158 def num(key: str) -> float | None:159 try:160 v = float((row.get(key) or "").strip())161 return v if v > 0 else None162 except ValueError:163 return None164165 rooms = (row.get("Type") or "").strip() # « 2 » … « 5 » -> n½166 unit_type = (f"{rooms}½" if rooms.isdigit() else "")167 price, area = num("Price"), num("Area")168 beds, baths = num("Chambers"), num("Bathrooms")169 balcony = num("Balcony")170171 desc = [f"Unité {unit} au Symbio, Terrebonne (Lachenaie)."]172 bits = []173 if area:174 bits.append(f"{area:g} pi²")175 if beds:176 bits.append(f"{beds:g} chambre(s)")177 if baths:178 bits.append(f"{baths:g} salle(s) de bain")179 if balcony:180 bits.append(f"balcon de {balcony:g} pi²")181 if bits:182 desc.append(", ".join(bits).capitalize() + ".")183184 images: list[str] = []185 pdf = (row.get("PDF") or "").strip()186 if pdf:187 images.append(f"{APP_BASE}/iframe/pdf/{pdf}.pdf")188189 listings.append(Listing(190 source=self.source_id,191 external_id=unit, # numéro d'unité : stable192 url=PAGE_URL, # pas de page publique/unité193 title=f"Symbio — unité {unit}",194 address=ADDRESS,195 sector="Lachenaie",196 city="Terrebonne",197 unit_type=unit_type,198 bedrooms=beds,199 bathrooms=baths,200 price=price,201 price_label=f"{price:.0f} $ /mois" if price else "",202 availability="Disponible",203 area_sqft=area,204 description=" ".join(desc),205 amenities=list(BUILDING_AMENITIES),206 details={"plan_pdf": images[0]} if images else {},207 images=[], # plans en PDF, pas de photos/unité208 ))209 return listings210