Files
voypace-ad-report/setup_on_adscenter.sh
T

71 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# =====================================================================
# 【在 ads-center 那台电脑上运行一次即可】
# 作用:
# 1) 拉取 Voypace 面板代码
# 2) 首次从 2026-07-15 全量回填数据并上线
# 3) 安装“每天早上 9 点自动更新”的定时任务
# 用法:把本文件拷到 ads-center,执行 bash setup_on_adscenter.sh
# =====================================================================
set -e
PY="/Users/ads-center/py314env/bin/python"
[ -x "$PY" ] || PY="python3"
BASE="/Users/ads-center/voypace-report-sync"
REPO_DIR="$BASE/voypace-ad-report"
REPO_URL="https://wangyuan:51fa1035659e6d267beffcd08af5ec7168efe4df@git.ops.roasbloom.site/wangyuan/voypace-ad-report.git"
PLIST_SRC="$REPO_DIR/com.voypace.dailysync.plist"
PLIST_DST="$HOME/Library/LaunchAgents/com.voypace.dailysync.plist"
echo ">>> 1/4 准备代码仓库..."
if [ -d "$REPO_DIR/.git" ]; then
git -C "$REPO_DIR" pull --rebase -q
else
mkdir -p "$BASE"
git clone -q "$REPO_URL" "$REPO_DIR"
fi
cd "$REPO_DIR"
echo ">>> 2/4 首次全量回填(从 2026-07-15,查数据库)..."
"$PY" db_fetch.py 2026-07-15 2026-12-31 > mtg_data.json
echo " 记录数:$("$PY" -c 'import json;print(len(json.load(open("mtg_data.json"))))')"
# 刷新矩阵状态
"$PY" - <<'EOF'
import json
from collections import defaultdict
data=json.load(open("mtg_data.json")); orders=json.load(open("orders.json"))
pkg_status={}
for o in orders:
for p in str(o["pkg"]).replace(" ","").split("/"):
if p: pkg_status[p]=o.get("status","Pause")
g=defaultdict(lambda: defaultdict(int))
for r in data: g[(r["channel"],r["pkg"])][r["date"]]+=r["impression"]
alldates=sorted(set(r["date"] for r in data)); last3=alldates[-3:]
ov={}
for (ch,pkg),days in g.items():
ps=pkg_status.get(pkg,"Pause")
if ps!="Active": ov[f"{ch}|{pkg}"]="Pause"; continue
total=sum(days.values()); rmax=max([days.get(dt,0) for dt in last3]) if last3 else 0
ov[f"{ch}|{pkg}"]= "none" if total==0 else ("Active" if rmax>=100 else "Pause")
json.dump(ov, open("matrix_overrides.json","w"), ensure_ascii=False, indent=2)
EOF
git add mtg_data.json matrix_overrides.json
git commit -m "data: full backfill from 2026-07-15" -q && git push -q origin main && echo " 已上线" || echo " 数据无变化"
echo ">>> 3/4 安装每日定时任务(每天 09:00)..."
mkdir -p "$HOME/Library/LaunchAgents"
cp "$PLIST_SRC" "$PLIST_DST"
# 先卸载旧的(若存在),再加载
launchctl unload "$PLIST_DST" 2>/dev/null || true
launchctl load "$PLIST_DST"
echo " 定时任务已安装:com.voypace.dailysync"
echo ">>> 4/4 校验..."
launchctl list | grep voypace || echo " (未在列表看到,可执行 launchctl list | grep voypace 复查)"
echo ""
echo "=== 全部完成! ==="
echo "面板地址:https://ops.roasbloom.site/voypace-ad-report/"
echo "以后每天 09:00 自动更新,日志:$BASE/voypace_sync.log"