#!/bin/bash
# Daily arXiv paper digest
# Run this via cron: 0 9 * * * ~/dev/arxiv-daily/run_daily.sh

cd "$(dirname "$0")"

LOG_FILE="arxiv_bot.log"
DIGEST_FILE="digest.md"
ARCHIVE_DIR="archive"

# Create archive directory
mkdir -p "$ARCHIVE_DIR"

# Run the bot
echo "[$(date)] Running arXiv bot..." >> "$LOG_FILE"

python3 arxiv_bot.py \
    --categories "cs.SD,cs.LG,cs.CL" \
    --days 1 \
    --threshold 0.15 \
    --output "$DIGEST_FILE" \
    >> "$LOG_FILE" 2>&1

# Check if successful
if [ -f "$DIGEST_FILE" ]; then
    echo "[$(date)] Digest created" >> "$LOG_FILE"

    # Archive previous digests
    DATE=$(date +%Y-%m-%d)
    cp "$DIGEST_FILE" "$ARCHIVE_DIR/digest_$DATE.md"

    # Optional: View digest
    # cat "$DIGEST_FILE"
else
    echo "[$(date)] No digest created" >> "$LOG_FILE"
fi

echo "[$(date)] Done" >> "$LOG_FILE"
