#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""probe_shaowu_args.py —— config args vs 手动跑的差异"""
import json, shlex, subprocess, time, re
D = "/root/gov_crawler/"
cfg = json.load(open(D + "daily_crawl_config.json", encoding="utf-8"))
lst = cfg if isinstance(cfg, list) else cfg.get("tasks", cfg.get("scripts", []))
ent = [c for c in lst if c.get("script") == "crawl_shaowu.py"]
print("config 条目:", json.dumps(ent[0], ensure_ascii=False) if ent else "（不在 config）")
args = (ent[0].get("args") or "") if ent else ""
print("args = %r" % args)
src = open(D + "crawl_shaowu.py", encoding="utf-8").read().split("\n")
print("\n=== main 关键段 L190-225 ===")
for i in range(189, min(225, len(src))):
    if src[i].strip(): print("  L%-4d %s" % (i + 1, src[i][:112]))
print("\n=== 按调度器方式跑（带 args）===")
t0 = time.time()
try:
    r = subprocess.run(["python3", D + "crawl_shaowu.py"] + shlex.split(args),
                       capture_output=True, text=True, timeout=100, cwd=D)
    print("EXIT=%d 耗时=%.1fs" % (r.returncode, time.time() - t0))
    for x in [y for y in (r.stdout or "").split("\n") if y.strip()][:6]:
        print("  out:", x[:112])
except subprocess.TimeoutExpired:
    print("⏱ >100s（说明带 args 也不是 0 秒）")
