Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/devloc.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/devloc.py : connecteur Devloc (devloc.ca / app.devloc.ca)91# L'inventaire vit dans l'ERP Laravel/Vue app.devloc.ca : l'API publique92# paginée GET /properties-public?page=N (Accept: application/json) retourne93# tout : type (TYPE_STUDIO/TYPE_3_5…), pi², loyer demandé, date de94# disponibilité, adresse géocodée (lat/lng), quartier (region.name), photos95# (uploads.devloc.ca), inclusions actives, tolérance chiens/chats et96# promotion. Seules les unités is_available (province QC) sont retenues.97# Une annonce par unité ; external_id = id numérique de l'ERP ;98# URL publique : https://app.devloc.ca/public/<slug>.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import re103104from ..schema import Listing105from .base import BaseConnector106107APP = "https://app.devloc.ca"108API_URL = f"{APP}/properties-public"109110TYPE_RE = re.compile(r"TYPE_(\d)_5")111_HEADERS = {"Accept": "application/json",112 "X-Requested-With": "XMLHttpRequest"}113_MAX_PAGES = 30 # garde-fou pagination114115116def _unit_type(t: str) -> str:117 if t == "TYPE_STUDIO":118 return "Studio"119 m = TYPE_RE.fullmatch(t or "")120 return f"{m.group(1)}½" if m else ""121122123def _pets(dog: bool | None, cat: bool | None) -> str | None:124 if dog is None and cat is None:125 return None126 if dog and cat:127 return "oui"128 if not dog and not cat:129 return "non"130 return "conditions"131132133class DevlocConnector(BaseConnector):134 source_id = "devloc"135 request_delay = 0.7136137 def fetch(self) -> list[Listing]:138 listings: list[Listing] = []139 page, last_page = 1, 1140 while page <= min(last_page, _MAX_PAGES):141 data = self.get(API_URL, params={"page": page},142 headers=_HEADERS).json()143 last_page = int((data.get("meta") or {}).get("last_page") or 1)144 for p in data.get("data") or []:145 try:146 lst = self._listing(p)147 if lst:148 listings.append(lst)149 except Exception:150 continue151 page += 1152 return listings153154 def _listing(self, p: dict) -> Listing | None:155 if not p.get("is_available"):156 return None157 adr = p.get("address") or {}158 if (adr.get("province") or "").strip().lower() != "qc":159 return None160 pid = str(p.get("id"))161 slug = p.get("slug") or pid162 street = (adr.get("address_1") or "").strip()163 unite = (adr.get("address_2") or "").strip()164 city = (adr.get("city") or "").strip() or "Montréal"165 postal = (adr.get("postal_code") or "").strip().upper()166 address = street + (f", app. {unite}" if unite else "")167 if city:168 address += f", {city}"169 if postal:170 address += f", QC {postal}"171 try:172 lat = float(adr["latitude"]) if adr.get("latitude") else None173 lng = float(adr["longitude"]) if adr.get("longitude") else None174 except (TypeError, ValueError):175 lat = lng = None176177 region = ((p.get("region") or {}).get("name") or "").strip()178 sector = "" if region.startswith("*") else region179180 ut = _unit_type(p.get("type") or "")181 price = p.get("property_status_asked_rent")182 try:183 price = float(price) if price else None184 except (TypeError, ValueError):185 price = None186 area = None187 try:188 area = float(p["square_feet_area"]) \189 if p.get("square_feet_area") else None190 except (TypeError, ValueError):191 pass192193 date = (p.get("availability_date")194 or p.get("property_status_starting_date") or "")[:10]195 availability = f"Disponible le {date}" if date else "Disponible"196197 amenities = [str(i.get("inclusion_label") or "").strip().capitalize()198 for i in (p.get("active_inclusions") or [])199 if i.get("inclusion_label")]200 if p.get("has_laundry_room"):201 amenities.append("Salle de lavage")202 if p.get("number_of_balconies"):203 amenities.append(f"{p['number_of_balconies']} balcon(s)")204205 desc = ""206 promo = (p.get("promotion") or "").strip()207 if promo:208 desc = f"Promotion : {promo}."209 notes = (p.get("tolerance_notes") or "").strip()210 if notes:211 desc = f"{desc} {notes}".strip()212213 titre_type = ut or "logement"214 return Listing(215 source=self.source_id,216 external_id=pid,217 url=f"{APP}/public/{slug}",218 title=f"{street} — {titre_type}" + (f" · app. {unite}"219 if unite else ""),220 address=address,221 sector=sector,222 city=city,223 unit_type=ut,224 price=price,225 price_label=f"{price:.0f} $" if price else "",226 availability=availability,227 availability_date=date if re.fullmatch(r"\d{4}-\d{2}-\d{2}",228 date) else None,229 area_sqft=area,230 pets=_pets(p.get("dog_tolerance"), p.get("cat_tolerance")),231 description=desc,232 amenities=amenities,233 images=[f.get("url") for f in (p.get("files") or [])234 if f.get("url")][:15],235 lat=lat,236 lng=lng,237 )238