Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/humano.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/humano.py : connecteur Humano District (humanodistrict.ca)91# Appartements locatifs au cœur de Sherbrooke — 2 bâtiments (Galt, 1820 rue92# Galt Ouest, et Maison Générale) sur l'ancien campus des sœurs. Le site WP93# embarque le widget SmartCondo Plans (silo.immo) : l'API JSON94# /v2/building/get-project-data?project=humano-district renvoie toutes les95# unités (prix, superficie, chambres, sdb, étage, disponibilité 1=dispo /96# 2=loué / 3=réservé + availability_date, plan PDF, photo). Granularité :97# unité.98# -----------------------------------------------------------------------------99from __future__ import annotations100101import re102import unicodedata103104from .base import BaseConnector105from ..schema import Listing106107SITE = "https://humanodistrict.ca/appartements/"108API = ("https://smartcondoplans.silo.immo/v2/building/get-project-data"109 "?project=humano-district&language=fr")110CDN = "https://smartcondoplans.silo.immo/"111112CITY = "Sherbrooke"113ADDRESSES = {114 "galt": "1820, rue Galt Ouest, Sherbrooke",115 "maison-generale": "rue Galt Ouest, Sherbrooke",116}117118TYPE_BY_ROOMS = {0: "Studio", 1: "3½", 2: "4½", 3: "5½"}119120121def _slug(s: str) -> str:122 s = unicodedata.normalize("NFKD", str(s)).encode("ascii", "ignore").decode()123 return re.sub(r"-+", "-", re.sub(r"[^a-z0-9]+", "-", s.lower())).strip("-")124125126class HumanoConnector(BaseConnector):127 source_id = "humano"128 request_delay = 0.6129130 def fetch(self) -> list[Listing]:131 listings: list[Listing] = []132 try:133 data = self.get(API).json()134 except Exception:135 return listings136137 # url de bâtiment par id (les unités référencent building via floors)138 bld_by_id = {b.get("id"): b for b in data.get("buildings", [])}139140 for u in data.get("project_units", []):141 try:142 if u.get("hide") or u.get("isnonunit") or u.get("not_unit"):143 continue144 avail = u.get("availability")145 date = (u.get("availability_date") or "").strip()146 if avail == 1:147 availability = (f"Disponible le {date}" if date148 else "Disponible")149 elif avail == 2 and date:150 availability = f"Disponible le {date}" # loué → se libère151 else:152 continue # loué sans date / réservé153154 name = str(u.get("name") or "").strip()155 if not name:156 continue157 bname = (u.get("building_name") or "").strip()158 burl = _slug(bname) if bname else "x"159 # retrouver l'url canonique du bâtiment si connue160 for b in bld_by_id.values():161 if b.get("name") == bname and b.get("url"):162 burl = b["url"]163 break164165 rooms = u.get("room")166 bathrooms = u.get("bathroom")167 unit_type = TYPE_BY_ROOMS.get(rooms, "")168 price = float(u["price"]) if u.get("price") else None169 area = float(u["area"]) if u.get("area") else None170171 furnished = bool(re.search(r"meubl", name, re.I))172 unit_no = re.sub(r"\s*-\s*Meubl[ée]s?$", "", name, flags=re.I)173174 details: dict = {}175 if u.get("floor_name"):176 details["floor"] = u["floor_name"]177 if bname:178 details["building"] = bname179 if furnished:180 details["furnished"] = True181 if u.get("file"):182 details["plan_pdf"] = CDN + u["file"].lstrip("/")183184 images = []185 if u.get("image"):186 images.append(CDN + u["image"].lstrip("/"))187188 listings.append(Listing(189 source=self.source_id,190 external_id=f"{burl}-{_slug(name)}",191 url=SITE,192 title=f"Unité {unit_no}"193 + (f" ({unit_type})" if unit_type else "")194 + (f" — {bname}, Humano District" if bname195 else " — Humano District"),196 address=ADDRESSES.get(burl, "rue Galt Ouest, Sherbrooke"),197 city=CITY,198 unit_type=unit_type,199 bedrooms=rooms if isinstance(rooms, int) else None,200 bathrooms=bathrooms if isinstance(bathrooms, int) else None,201 price=price,202 availability=availability,203 area_sqft=area,204 details=details,205 images=images,206 ))207 except Exception:208 continue209 return listings210