#!/bin/bash
# push_brief_to_gitea.sh
# 日报生成后推送至 Gitea
# 由 daily_brief.py 在生成日报后调用，或 cron 单独执行
# 用法：bash scripts/push_brief_to_gitea.sh [日期 YYYY-MM-DD]

BRIEF_DATE="${1:-$(date +%Y-%m-%d)}"
BRIEF_FILE="/home/ubuntu/freqtrade/user_data/daily_briefs/${BRIEF_DATE}.txt"
REPO_DIR="/home/ubuntu/beast-trader"
DEST_DIR="${REPO_DIR}/daily_briefs/$(echo ${BRIEF_DATE} | cut -d- -f1)"

mkdir -p "${DEST_DIR}"

if [ -f "${BRIEF_FILE}" ]; then
    cp "${BRIEF_FILE}" "${DEST_DIR}/${BRIEF_DATE}.txt"
    cd "${REPO_DIR}"
    git add "daily_briefs/"
    git commit -m "brief: auto push ${BRIEF_DATE}" --allow-empty
    git push
    echo "Brief ${BRIEF_DATE} pushed to Gitea"
else
    echo "Brief file not found: ${BRIEF_FILE}"
    exit 1
fi
