Repository Public
1#!/usr/bin/env python32# -----------------------------------------------------------------------------3# Lou-Ka — Agrégateur de logements à louer (province de Québec)4# Auteur : Simon-Pierre Boucher — contact@spboucher.ai5# run.py : point d'entrée — `sync`, `watch`, `serve`6# -----------------------------------------------------------------------------7"""Utilisation :8 python run.py sync [source ...] # synchronise les annonces9 python run.py watch [minutes] # synchronise en boucle (défaut 60 min)10 python run.py serve [port] # démarre l'API + le frontend (défaut 8080)11 python run.py record <source ...> # enregistre les fixtures de test d'une source12"""13from __future__ import annotations1415import os16import sys17from pathlib import Path1819# Charger .env (FIRECRAWL_API_KEY, etc.) sans dépendance externe20_env = Path(__file__).parent / ".env"21if _env.exists():22 for line in _env.read_text().splitlines():23 line = line.strip()24 if line and not line.startswith("#") and "=" in line:25 k, _, v = line.partition("=")26 os.environ.setdefault(k.strip(), v.strip())272829def main() -> None:30 cmd = sys.argv[1] if len(sys.argv) > 1 else "serve"31 if cmd == "sync":32 from louka import ingest33 ingest.run(sys.argv[2:] or None)34 elif cmd == "watch":35 from louka import ingest36 minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 6037 ingest.watch(minutes * 60)38 elif cmd == "record":39 from louka import fixtures40 from louka.connectors import CONNECTORS41 targets = sys.argv[2:] or sorted(CONNECTORS)42 for sid in targets:43 try:44 print(f"[lou-ka] record {sid} ... {fixtures.record(sid)}")45 except Exception as exc:46 print(f"[lou-ka] record {sid} ÉCHEC : {exc}", file=sys.stderr)47 elif cmd == "serve":48 import uvicorn49 port = int(sys.argv[2]) if len(sys.argv) > 2 else 808050 uvicorn.run("louka.web:app", host="0.0.0.0", port=port)51 else:52 print(__doc__)53 sys.exit(1)545556if __name__ == "__main__":57 main()58