#!/usr/bin/env python3 # ============================================================================== # Author: Simon-Pierre Boucher # File: run.py # Desc: Point d'entrée Créa-Ka — `sync`, `watch`, `serve` (calqué sur Lou-Ka) # ============================================================================== """Utilisation : python run.py sync [source ...] # synchronise (découverte + enrichissement) python run.py watch [heures] # synchronise en boucle (défaut 24 h) python run.py serve [port] # démarre l'API + le frontend (défaut 8160) python run.py optout # retrait manuel immédiat """ from __future__ import annotations import os import sys from pathlib import Path # Charger .env (SCRAPFLY_KEY, FIRECRAWL_API_KEY, YOUTUBE_API_KEY…) sans dépendance _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 creaka import ingest ingest.run(sys.argv[2:] or None) elif cmd == "watch": from creaka import ingest hours = float(sys.argv[2]) if len(sys.argv) > 2 else 24.0 ingest.watch(int(hours * 3600)) elif cmd == "optout": if len(sys.argv) < 3: print(__doc__) sys.exit(1) from creaka import db, ethics target = sys.argv[2] is_account = ":" in target ethics.add_optout(name=None if is_account else target, account=target if is_account else None, reason="retrait manuel (CLI)") n = db.apply_optout(db.connect(), name=None if is_account else target, account=target if is_account else None) print(f"[crea-ka] opt-out enregistré, {n} fiche(s) masquée(s)") elif cmd == "serve": import uvicorn port = int(sys.argv[2]) if len(sys.argv) > 2 else 8160 uvicorn.run("creaka.web:app", host="0.0.0.0", port=port) else: print(__doc__) sys.exit(1) if __name__ == "__main__": main()