This repository has no description
1#!/usr/bin/env python3
2"""Container entrypoint for the daily Tangled sync job."""
3
4from __future__ import annotations
5
6import argparse
7import os
8import sys
9from pathlib import Path
10
11from dotenv import load_dotenv
12
13from daily_issue_scraper.pipeline import run_daily_sync
14
15REPO_ROOT = Path(__file__).resolve().parent.parent
16
17
18def load_env() -> None:
19 for candidate in (
20 REPO_ROOT / ".env",
21 Path(__file__).resolve().parent / ".env",
22 REPO_ROOT / "scraper" / ".env",
23 ):
24 if candidate.exists():
25 load_dotenv(candidate)
26 return
27 load_dotenv()
28
29
30def require_dsn() -> str:
31 dsn = os.getenv("DB_CONNECTION_STRING", "").strip()
32 if not dsn:
33 print("ERROR: DB_CONNECTION_STRING is not set", file=sys.stderr)
34 raise SystemExit(1)
35 return dsn
36
37
38def main(argv: list[str] | None = None) -> None:
39 parser = argparse.ArgumentParser(description="Run the daily Tangled sync pipeline.")
40 parser.add_argument(
41 "--only",
42 nargs="+",
43 metavar="STAGE",
44 help="Run specific stages only (network, accounts, repos, issues, readmes, ...)",
45 )
46 args = parser.parse_args(argv)
47
48 load_env()
49 dsn = require_dsn()
50 only = set(args.only) if args.only else None
51 run_daily_sync(dsn, only=only)
52
53
54if __name__ == "__main__":
55 try:
56 main()
57 except KeyboardInterrupt:
58 print("\nInterrupted.", file=sys.stderr)
59 raise SystemExit(130) from None