Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : louka/connectors/levivo.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/levivo.py : connecteur LeVivo Condos Locatifs (levivo.ca)91# Quatre projets « tout inclus » en Montérégie : Longueuil 1, Longueuil 2,92# Greenfield Park et La Prairie. Squarespace rendu serveur : chaque page93# /fr/projets/<slug> affiche l'adresse (ligne au-dessus de « Adresse »)94# puis une « Description des unités » en triplets texte (« 4 ½ / À partir95# de / 2 100,00 $ »). Granularité : typologie par projet.96# -----------------------------------------------------------------------------97from __future__ import annotations9899import re100101from bs4 import BeautifulSoup102103from .base import BaseConnector104from ..schema import Listing, normalize_unit_type105106BASE = "https://www.levivo.ca"107108PROJECTS = [109 ("longueuil-1", "LeVivo Longueuil 1", "Longueuil"),110 ("longueuil-2", "LeVivo Longueuil 2", "Longueuil"),111 ("greenfield-park", "LeVivo Greenfield Park", "Longueuil"),112 ("la-prairie", "LeVivo La Prairie", "La Prairie"),113]114115TYPE_RE = re.compile(r"^(studio|\d\s*½|\d\s*1/2)$", re.I)116# « 2 100,00 $ » (format québécois)117PRICE_RE = re.compile(r"^([\d\s ]{1,3}(?:[\s ]?\d{3})*),\d{2}\s*\$$")118IMG_RE = re.compile(r'https://images\.squarespace-cdn\.com/content/'119 r'[^"\s\\)]+\.(?:jpe?g|png|webp)', re.I)120121122class LevivoConnector(BaseConnector):123 source_id = "levivo"124 request_delay = 0.6125126 def fetch(self) -> list[Listing]:127 listings: list[Listing] = []128 for slug, name, city in PROJECTS:129 url = f"{BASE}/fr/projets/{slug}"130 try:131 html = self.get(url).text132 except Exception:133 continue134 soup = BeautifulSoup(html, "html.parser")135 lines = soup.get_text("\n", strip=True).split("\n")136137 # adresse : la ligne complète précède le libellé « Adresse »138 address = ""139 for i, line in enumerate(lines):140 if line.strip() == "Adresse" and i > 0:141 address = lines[i - 1].strip()142 break143 address = re.sub(r",?\s*Québec(\s+\w\d\w\s*\d\w\d)?$", "",144 address).strip().rstrip(",")145146 images = [u for u in dict.fromkeys(IMG_RE.findall(html))147 if not re.search(r"favicon|logo|icon", u, re.I)][:15]148149 # triplets « 4 ½ / À partir de / 2 100,00 $ »150 for i, line in enumerate(lines):151 raw = line.strip()152 if not TYPE_RE.match(raw):153 continue154 if i + 2 >= len(lines):155 continue156 if not lines[i + 1].strip().lower().startswith("à partir"):157 continue158 m = PRICE_RE.match(lines[i + 2].strip())159 if not m:160 continue161 try:162 price = float(m.group(1).replace(" ", "")163 .replace(" ", "").replace(" ", ""))164 except ValueError:165 continue166 unit_type = ("Studio" if raw.lower() == "studio"167 else normalize_unit_type(raw))168 type_slug = ("studio" if unit_type == "Studio"169 else unit_type.replace("½", ".5"))170 ext_id = f"{slug}-{type_slug}"171 if any(l.external_id == ext_id for l in listings):172 continue173 listings.append(Listing(174 source=self.source_id,175 external_id=ext_id,176 url=url,177 title=f"{unit_type} — {name}",178 address=address or None,179 city=city,180 unit_type=unit_type,181 price=price,182 price_label=f"À partir de {lines[i + 2].strip()}",183 description=f"Condos locatifs « tout inclus » du projet "184 f"{name} : électricité, chauffage, eau "185 f"chaude, internet et câblodistribution "186 f"inclus, avec piscine et salle d'exercice.",187 images=images,188 ))189 return listings190