Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : KA Enrich7# File : kaenrich/sites/louka.py8# Module : Kaenrich9# Repository : https://git.spboucher.ai/ka-enrich10# Project Website : Not specified11# Created : 2026-12-0312# Last Modified : 2026-12-0313#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: contact@spboucher.ai22# Development : dev@spboucher.ai23# Support : support@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041"""Adaptateur Lou-Ka : dépose les annonces à lire et range les faits reçus.4243Tourne sur le nœud de la base Lou-Ka. N'écrit que dans les tables `llm_facts`44et `llm_pending` ; la fusion dans les annonces appartient à Lou-Ka.4546 python -m kaenrich.sites.louka export --db data/louka.db --root /opt/efs/shared/ka-enrich/exchange47 python -m kaenrich.sites.louka import --db data/louka.db --root /opt/efs/shared/ka-enrich/exchange48 python -m kaenrich.sites.louka sync --db data/louka.db --root /opt/efs/shared/ka-enrich/exchange49"""50from __future__ import annotations5152import sqlite35354from . import _exchange as ex5556SITE = "louka"57MIN_CHARS = ex.MIN_CHARS58text_hash = ex.text_hash596061def missing_fields(row: sqlite3.Row) -> list[str]:62 """Champs encore inconnus de l'annonce, donc à demander au modèle."""63 details = ex.loads(row["details"], {})64 faits = ex.loads(row["digest"], {}).get("faits") or {}65 want = []66 if row["area_sqft"] is None:67 want.append("area_sqft")68 if row["bathrooms"] is None:69 want.append("bathrooms")70 if row["availability_date"] is None:71 want.append("availability")72 if not row["pets"]:73 want.append("pets")74 if row["furnished"] is None and details.get("furnished") is None:75 want.append("furnished")76 if not any(details.get(k) for k in ("construction_year", "Année de construction", "year_built")):77 want.append("construction_year")78 if not isinstance(details.get("parking"), dict):79 want += ["parking", "parking_price"]80 elif details["parking"].get("included") is None and not details["parking"].get("price"):81 want += ["parking", "parking_price"]82 if details.get("floor") is None:83 want.append("floor")84 if details.get("smoking") is None:85 want.append("smoking")86 if not faits.get("duree_bail_minimale_mois"):87 want.append("lease_min_months")88 if not faits.get("depot_mentionne"):89 want.append("deposit")90 want += ["credit_check", "references", "insurance"]91 return want929394CONFIG = ex.Site(95 name=SITE,96 profile="louka",97 select=("SELECT uid, source, title, unit_type, description, area_sqft, bathrooms, "98 "availability_date, pets, furnished, details, digest FROM listings "99 "WHERE active=1 AND published=1 AND length(description) >= ?"),100 missing=missing_fields,101 context=lambda r: {"title": r["title"] or "", "kind": r["unit_type"] or ""},102 floor=4, # s'il ne manque que les trois conditions, rien à gagner103)104105106def export(db, root, limit, batch, all_fields, source, tag, track=False) -> int:107 return ex.export(CONFIG, db, root, limit, batch, all_fields, source, tag, track)108109110def import_results(db, root) -> int:111 return ex.import_results(CONFIG, db, root)112113114def backlog(root) -> int:115 return ex.backlog(CONFIG, root)116117118def main(argv=None) -> int:119 return ex.main(CONFIG, __doc__, argv)120121122if __name__ == "__main__":123 raise SystemExit(main())124