Publish top10 KA FFR report

This commit is contained in:
SHAREit
2026-09-01 15:22:45 +08:00
parent caf98a8c09
commit 16be038cf0
3 changed files with 615 additions and 232 deletions
+25 -3
View File
@@ -576,13 +576,35 @@ def main():
sheets = config["sheets"]
now = datetime.now(TIMEZONE)
end_date = now.date() - timedelta(days=1)
start_date = end_date.replace(day=1)
# 默认当月 1 号至昨天;--month YYYY-MM 可指定月份(如已结束的月份则取整月)
month_arg = next((item.split("=", 1)[-1] for item in sys.argv[2:] if item.startswith("--month")), None)
if month_arg:
year, month = (int(part) for part in month_arg.split("-")[:2])
start_date = datetime(year, month, 1).date()
else:
start_date = (now.date() - timedelta(days=1)).replace(day=1)
month_end = (start_date.replace(day=28) + timedelta(days=4)).replace(day=1) - timedelta(days=1)
end_date = min(month_end, now.date() - timedelta(days=1))
if end_date < start_date:
raise SystemExit(f"指定月份 {start_date:%Y-%m} 尚无已结束的日期")
days = (end_date - start_date).days + 1
month_days = ((start_date.replace(day=28) + timedelta(days=4)).replace(day=1) - timedelta(days=1)).day
month_days = month_end.day
print(f"取数范围:{start_date} 至 {end_date}({days}/{month_days} 天)")
sands = load_sands()
# 判断 Cost 是否滞后于数据周期:抓取日在周期结束日当天或更早,说明未覆盖完整周期
if sands and sands.get("fetched_at"):
try:
fetched = datetime.fromisoformat(sands["fetched_at"]).date()
except ValueError:
fetched = None
if fetched:
sands["fetched_date"] = fetched.isoformat()
lag = (end_date - fetched).days + 1
sands["lag_days"] = max(0, lag)
sands["stale"] = lag > 0
if sands["stale"]:
print(f"警告:Sands Cost 抓取于 {fetched},可能未覆盖到 {end_date},滞后约 {lag} 天")
try:
target_rows, _ = fetch_rows(config["target_spreadsheet_id"], config["target_gid"])
targets = read_targets(target_rows)