#!/bin/bash
# Cron script to update NBA data
# Add to crontab: */30 * * * * /var/www/html/eventheodds/scripts/cron-update-nba-data.sh
#
# This script:
# 1. Fetches live NBA games and odds from ESPN
# 2. Updates player rosters
# 3. Saves data to JSON files for quick access

cd /var/www/html/eventheodds

echo "[$(date)] Starting NBA data update..."

# Fetch live games and save to JSON
npx tsx scripts/fetch-live-nba-data.ts --save 2>&1 | tee -a logs/nba-live-data.log

# Sync rosters from ESPN (once daily is enough)
HOUR=$(date +%H)
if [ "$HOUR" == "06" ]; then
    echo "[$(date)] Running daily roster sync..."
    npx tsx scripts/sync-rosters.ts --league=nba 2>&1 | tee -a logs/roster-sync.log
fi

echo "[$(date)] NBA data update complete"
