Update report UI and month-to-date metrics
This commit is contained in:
+11
-2
@@ -23,6 +23,8 @@ CSV_URL = (
|
||||
)
|
||||
TIMEZONE = ZoneInfo("Asia/Shanghai")
|
||||
COUNTRIES = ["KZ", "UZ", "KG", "AM"]
|
||||
# 平台只支持“每隔几小时”,因此按小时调度,仅在此时刻真正更新(Asia/Shanghai)
|
||||
UPDATE_HOUR = 11
|
||||
|
||||
DATE_HEADERS = {"date"}
|
||||
GEO_HEADERS = {"geo", "country"}
|
||||
@@ -243,12 +245,19 @@ def build_payload(rows, now):
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit("用法: update_report_data.py <输出文件>")
|
||||
raise SystemExit("用法: update_report_data.py <输出文件> [--force]")
|
||||
|
||||
now = datetime.now(TIMEZONE)
|
||||
forced = "--force" in sys.argv[2:]
|
||||
if not forced and now.hour != UPDATE_HOUR:
|
||||
print(f"SKIP {now:%Y-%m-%d %H:%M} 非 {UPDATE_HOUR}:00(Asia/Shanghai),不更新")
|
||||
return
|
||||
|
||||
request = urllib.request.Request(CSV_URL, headers={"User-Agent": "AgentStage-Ozon-Report/2.0"})
|
||||
with urllib.request.urlopen(request, timeout=90) as response:
|
||||
text = response.read().decode("utf-8-sig")
|
||||
rows = list(csv.reader(text.splitlines()))
|
||||
payload = build_payload(rows, datetime.now(TIMEZONE))
|
||||
payload = build_payload(rows, now)
|
||||
with open(sys.argv[1], "w", encoding="utf-8") as handle:
|
||||
json.dump(payload, handle, ensure_ascii=False, indent=2)
|
||||
period = payload["period"]
|
||||
|
||||
Reference in New Issue
Block a user