#!/usr/bin/env python3 # ----------------------------------------------------------------------------- # Food-Ka — Agrégateur de produits d'épicerie (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 produits python run.py watch [minutes] # synchronise en boucle (défaut 360 min) python run.py serve [port] # démarre l'API + le frontend (défaut 8080) """ from __future__ import annotations import os import sys from pathlib import Path # Charger .env (SCRAPFLY_API_KEY, FIRECRAWL_API_KEY…) 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 foodka import ingest ingest.run(sys.argv[2:] or None) elif cmd == "watch": from foodka import ingest minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 360 ingest.watch(minutes * 60) elif cmd == "serve": import uvicorn port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080 uvicorn.run("foodka.web:app", host="0.0.0.0", port=port) else: print(__doc__) sys.exit(1) if __name__ == "__main__": main()