Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : Lou·Ka10# File : tests/run.py11# Module : tests12# Repository : https://git.spboucher.ai/lou-ka13# Created : 2026-08-1814# Last Modified : 2026-08-1815#16# =============================================================================17# AUTHOR & PROFESSIONAL AFFILIATION18# =============================================================================19#20# Author : Simon-Pierre Boucher21# Position : Professor of Finance22# Institution : Université du Québec en Outaouais (UQO)23# Department : Département des sciences administratives24# Organization : SP Boucher25#26# Website : https://spboucher.ai27# Git : https://git.spboucher.ai28#29# =============================================================================30# OFFICIAL CONTACT DIRECTORY31# =============================================================================32#33# General : info@spboucher.ai34# Professional : contact@spboucher.ai35# Direct : simon@spboucher.ai36# Research : research@spboucher.ai37# Development : dev@spboucher.ai38# Support : support@spboucher.ai39# Security/Admin : admin@spboucher.ai40# Notifications : notifications@spboucher.ai41#42# Preferred Contact: contact@spboucher.ai43#44# =============================================================================45# COPYRIGHT & INTELLECTUAL PROPERTY46# =============================================================================47#48# Copyright (c) 202649# Simon-Pierre Boucher50#51# All rights reserved where applicable.52#53# This file is governed by the applicable project license,54# copyright notices, institutional agreements and relevant law.55#56# Unless expressly authorized by the applicable license or57# rights holder, copying, redistribution, sublicensing,58# publication and commercial exploitation are not permitted.59#60# Existing third-party rights and notices remain unaffected.61#62# =============================================================================63# CONFIDENTIALITY & SECURITY64# =============================================================================65#66# Classification : Public67# Distribution : Public repository; use is governed by the project license68# Security Contact : admin@spboucher.ai69#70# Access to this source does not independently grant permission71# to redistribute or disclose confidential materials.72#73# Do not embed credentials, private keys, access tokens,74# certificates or confidential personal information.75#76# =============================================================================77# LICENSE & MAINTENANCE78# =============================================================================79#80# License : None specified (no license file in this repository)81# Maintainer : Simon-Pierre Boucher82# Technical Contact: dev@spboucher.ai83#84# =============================================================================85# END OF SP BOUCHER SOURCE HEADER86# =============================================================================8788# -----------------------------------------------------------------------------89# Lou-Ka — Agrégateur de logements à louer (province de Québec)90# Auteur : Simon-Pierre Boucher — contact@spboucher.ai91# run.py : point d'entrée — `sync`, `watch`, `serve`92# -----------------------------------------------------------------------------93"""Utilisation :94 python run.py sync [source ...] # synchronise les annonces95 python run.py watch [minutes] # synchronise en boucle (défaut 60 min)96 python run.py serve [port] # démarre l'API + le frontend (défaut 8080)97 python run.py record <source ...> # enregistre les fixtures de test d'une source98 python run.py geocode [n] # géocode les annonces sans coordonnées (max n requêtes)99 python run.py poi [n] # commodités de proximité par immeuble (max n requêtes)100 python run.py env [n] # environnement OSM par tuile (socle des KA Scores)101 python run.py kascores [all] # calcule les KA Scores du parc (all = tout recalculer)102"""103from __future__ import annotations104105import os106import sys107from pathlib import Path108109# Charger .env (FIRECRAWL_API_KEY, etc.) sans dépendance externe110_env = Path(__file__).parent / ".env"111if _env.exists():112 for line in _env.read_text().splitlines():113 line = line.strip()114 if line and not line.startswith("#") and "=" in line:115 k, _, v = line.partition("=")116 os.environ.setdefault(k.strip(), v.strip())117118119def main() -> None:120 cmd = sys.argv[1] if len(sys.argv) > 1 else "serve"121 if cmd == "sync":122 from louka import ingest123 ingest.run(sys.argv[2:] or None)124 elif cmd == "watch":125 from louka import ingest126 minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 60127 ingest.watch(minutes * 60)128 elif cmd == "geocode1":129 from louka import geocode130 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None131 geocode.run(limit)132 elif cmd == "geocode":133 # lot Adresses Québec (rapide) ; « geocode1 » = ancien mode 1-par-1134 from louka import geocode135 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None136 geocode.run_batch(limit)137 elif cmd == "quality":138 # (re)calcule le score de complétude + publication/quarantaine139 from louka import quality140 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None141 quality.backfill(limit)142 elif cmd == "imgaudit":143 # contrôle qualité des images (liens morts, minuscules, placeholders,144 # doublons) — incrémental : python run.py imgaudit [n_annonces] [source]145 from louka import imgcheck146 limit = int(sys.argv[2]) if len(sys.argv) > 2 else 1500147 src = sys.argv[3] if len(sys.argv) > 3 else None148 imgcheck.run(limit, source=src)149 elif cmd == "fairvalue":150 # (re)calcule la juste valeur locative de toutes les annonces publiées151 from louka import fairvalue152 fairvalue.compute_all()153 elif cmd == "poi":154 from louka import poi155 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None156 poi.run(limit)157 elif cmd == "quartier":158 from louka import quartier159 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None160 quartier.enrich(limit)161 elif cmd == "env":162 # données d'environnement OSM par tuile (routes, rails, cyclable,163 # bars, POI complets) — cache ~3 mois, socle des KA Scores164 from louka import environment165 limit = int(sys.argv[2]) if len(sys.argv) > 2 else None166 print(environment.run(limit))167 elif cmd == "kascores":168 # (re)calcule les KA Scores (Walk/Transit/Bike/Calme/Services + global)169 # incrémental ; « python run.py kascores all » force tout le parc170 from louka import kascores171 force = len(sys.argv) > 2 and sys.argv[2] == "all"172 print(kascores.run(recompute_all=force))173 elif cmd == "record":174 from louka import fixtures175 from louka.connectors import CONNECTORS176 targets = sys.argv[2:] or sorted(CONNECTORS)177 for sid in targets:178 try:179 print(f"[lou-ka] record {sid} ... {fixtures.record(sid)}")180 except Exception as exc:181 print(f"[lou-ka] record {sid} ÉCHEC : {exc}", file=sys.stderr)182 elif cmd == "serve":183 import uvicorn184 port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080185 uvicorn.run("louka.web:app", host="0.0.0.0", port=port)186 else:187 print(__doc__)188 sys.exit(1)189190191if __name__ == "__main__":192 main()193