#!/usr/bin/env python3 # ----------------------------------------------------------------------------- # Lou-Ka — Agrégateur de logements à louer (province de Québec) # Auteur : Simon-Pierre Boucher — contact@spboucher.ai # run.py : point d'entrée — `sync`, `watch`, `serve` # ----------------------------------------------------------------------------- """Utilisation : python run.py sync [source ...] # synchronise les annonces python run.py watch [minutes] # synchronise en boucle (défaut 60 min) python run.py serve [port] # démarre l'API + le frontend (défaut 8080) python run.py record # enregistre les fixtures de test d'une source python run.py geocode [n] # géocode les annonces sans coordonnées (max n requêtes) python run.py poi [n] # commodités de proximité par immeuble (max n requêtes) """ from __future__ import annotations import os import sys from pathlib import Path # Charger .env (FIRECRAWL_API_KEY, etc.) sans dépendance externe _env = Path(__file__).parent / ".env" if _env.exists(): for line in _env.read_text().splitlines(): line = line.strip() if line and not line.startswith("#") and "=" in line: k, _, v = line.partition("=") os.environ.setdefault(k.strip(), v.strip()) def main() -> None: cmd = sys.argv[1] if len(sys.argv) > 1 else "serve" if cmd == "sync": from louka import ingest ingest.run(sys.argv[2:] or None) elif cmd == "watch": from louka import ingest minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 60 ingest.watch(minutes * 60) elif cmd == "geocode": from louka import geocode limit = int(sys.argv[2]) if len(sys.argv) > 2 else None geocode.run(limit) elif cmd == "poi": from louka import poi limit = int(sys.argv[2]) if len(sys.argv) > 2 else None poi.run(limit) elif cmd == "quartier": from louka import quartier limit = int(sys.argv[2]) if len(sys.argv) > 2 else None quartier.enrich(limit) elif cmd == "record": from louka import fixtures from louka.connectors import CONNECTORS targets = sys.argv[2:] or sorted(CONNECTORS) for sid in targets: try: print(f"[lou-ka] record {sid} ... {fixtures.record(sid)}") except Exception as exc: print(f"[lou-ka] record {sid} ÉCHEC : {exc}", file=sys.stderr) elif cmd == "serve": import uvicorn port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080 uvicorn.run("louka.web:app", host="0.0.0.0", port=port) else: print(__doc__) sys.exit(1) if __name__ == "__main__": main()