SPB Git

spb/lou-ka Public

Lou·Ka — tous les logements à louer du Québec, un seul endroit.

HTML 99.7%
2.7 KB · 72 lines python
Raw Blame History
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    python run.py geocode [n]           # géocode les annonces sans coordonnées (max n requêtes)13    python run.py poi [n]               # commodités de proximité par immeuble (max n requêtes)14"""15from __future__ import annotations1617import os18import sys19from pathlib import Path2021# Charger .env (FIRECRAWL_API_KEY, etc.) sans dépendance externe22_env = Path(__file__).parent / ".env"23if _env.exists():24    for line in _env.read_text().splitlines():25        line = line.strip()26        if line and not line.startswith("#") and "=" in line:27            k, _, v = line.partition("=")28            os.environ.setdefault(k.strip(), v.strip())293031def main() -> None:32    cmd = sys.argv[1] if len(sys.argv) > 1 else "serve"33    if cmd == "sync":34        from louka import ingest35        ingest.run(sys.argv[2:] or None)36    elif cmd == "watch":37        from louka import ingest38        minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 6039        ingest.watch(minutes * 60)40    elif cmd == "geocode":41        from louka import geocode42        limit = int(sys.argv[2]) if len(sys.argv) > 2 else None43        geocode.run(limit)44    elif cmd == "poi":45        from louka import poi46        limit = int(sys.argv[2]) if len(sys.argv) > 2 else None47        poi.run(limit)48    elif cmd == "quartier":49        from louka import quartier50        limit = int(sys.argv[2]) if len(sys.argv) > 2 else None51        quartier.enrich(limit)52    elif cmd == "record":53        from louka import fixtures54        from louka.connectors import CONNECTORS55        targets = sys.argv[2:] or sorted(CONNECTORS)56        for sid in targets:57            try:58                print(f"[lou-ka] record {sid} ... {fixtures.record(sid)}")59            except Exception as exc:60                print(f"[lou-ka] record {sid} ÉCHEC : {exc}", file=sys.stderr)61    elif cmd == "serve":62        import uvicorn63        port = int(sys.argv[2]) if len(sys.argv) > 2 else 808064        uvicorn.run("louka.web:app", host="0.0.0.0", port=port)65    else:66        print(__doc__)67        sys.exit(1)686970if __name__ == "__main__":71    main()72