#!/usr/bin/env python3
"""
Daily data update script.
Run this via cron to keep indicator data fresh.

Example crontab (daily at 9:00 AM):
    0 9 * * * cd /path/to/btc-bottom-panel && python3 daily_update.py
"""

import subprocess
import sys
from datetime import datetime, timezone
from pathlib import Path

ROOT = Path(__file__).parent
FETCHER = ROOT / "backend" / "fetch_data.py"

def main():
    print(f"[{datetime.now(timezone.utc).isoformat()}] Starting daily update...")
    result = subprocess.run(
        [sys.executable, str(FETCHER)],
        capture_output=True,
        text=True,
    )
    print(result.stdout)
    if result.stderr:
        print(result.stderr, file=sys.stderr)
    if result.returncode != 0:
        print(f"[ERROR] Update failed with code {result.returncode}")
        sys.exit(1)
    print("[INFO] Daily update complete.")

if __name__ == "__main__":
    main()
