#!/bin/bash
# Daily crypto news/briefing capture — runs via cron
# Saves to results/ and memory/ for historical reference
#
# Usage: cron_news.sh
# Cron: 0 8 * * * (daily at 8 AM UTC)

cd /var/www/html/crpytotradingbot

DATE=$(date +%Y-%m-%d)
MEMORY_DIR="/home/administrator/.openclaw/agents/cryptoclaw/workspace/memory"
mkdir -p "$MEMORY_DIR"

echo "=== Crypto News Capture: $DATE ==="

# Run the daily briefing and save
OUTPUT=$(python3 daily_briefing.py --save 2>&1)
BRIEFING_FILE=$(ls -t results/briefing_*.txt 2>/dev/null | head -1)

if [ -z "$BRIEFING_FILE" ]; then
    echo "ERROR: No briefing file generated"
    exit 1
fi

echo "Briefing saved: $BRIEFING_FILE"

# Append to daily memory log
MEMORY_FILE="$MEMORY_DIR/$DATE.md"

{
    echo ""
    echo "## Daily Briefing — $DATE"
    echo ""
    cat "$BRIEFING_FILE"
    echo ""
} >> "$MEMORY_FILE"

echo "Appended to memory: $MEMORY_FILE"
echo "Done."
