Files
Manta-tracking-new/update.sh
T

20 lines
934 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# AgentStage runs this hourly. The guard below refreshes once after 12:00 Asia/Shanghai.
export TZ=Asia/Shanghai
hour="$(date +%H)"
target_date="$(date -v-1d +%F 2>/dev/null || date -d yesterday +%F)"
if [ "$hour" -lt 12 ]; then exit 0; fi
: "${TABLEAU_COOKIE:?Set TABLEAU_COOKIE in the AgentStage runner secret environment}"
base_url="${TABLEAU_CSV_URL:-https://mars.ushareit.org/views/DSPSpend/DSPDailyData.csv}"
tmp_file="$(mktemp)"
trap 'rm -f "$tmp_file"' EXIT
pkg_csv="$(python3 -c 'import json; d=json.load(open("campaign_config.json")); print(",".join(sorted({r["pkg"] for r in d if r["status"].lower()=="active"})))')"
query="?:showVizHome=no&dt=${target_date}&pkg=${pkg_csv}&维度1=pkg&维度2=campaign_name&Source=展开&source=bigo,kwai,mintegral"
curl -fsSL --cookie "$TABLEAU_COOKIE" "${base_url}${query}" -o "$tmp_file"
python3 transform_tableau.py "$tmp_file" "$target_date"