| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- """seed_insight_link.py —— 把归纳区与报告层打通示例样本(可重复执行)。
- 库里现有 4 条归纳的支撑成果(derivedArtifacts)都来自李娜 / 王芳 / 刘洋,示例报告挂在张伟那份成果上,
- 所以"归纳 → 归纳自哪几份报告"这条链路没有可看的样本。本脚本:
- 1. 在归纳「夜宵场景对低卡有明确诉求」的证据链里补一条张伟的成果(示例报告加载的那条),
- 并把对应的结论 c-texture / c-price 记进 citedInsightIds —— 这样这条归纳的支撑成果里就有一份带报告的成果;
- 2. 归纳页会出现「归纳自 N 份报告」,展开能看到报告与它引用的结论,可点进报告 / 证据链。
- 只在库里确有"示例报告"时才执行;不新增数据,只补充交叉引用。
- python3 tools/seed_insight_link.py --dry-run
- python3 tools/seed_insight_link.py
- """
- import json, os, sys, urllib.request
- BASE = "https://kangshifu.fmode.cn/parse"
- APP_ID = "FKieRbIoGt_main"
- MK = os.environ.get("PARSE_MASTER_KEY", "")
- DRY = "--dry-run" in sys.argv
- H = {"X-Parse-Application-Id": APP_ID, "Content-Type": "application/json"}
- if MK:
- H["X-Parse-Master-Key"] = MK
- INSIGHT_TITLE = "夜宵场景对低卡有明确诉求"
- REPORT_OWNER = "张伟" # 示例报告挂在张伟的成果上
- CONCL = ["c-texture", "c-price"]
- def call(m, p, b=None):
- data = json.dumps(b, ensure_ascii=False).encode() if b is not None else None
- r = urllib.request.Request(BASE + p, data=data, headers=H, method=m)
- with urllib.request.urlopen(r, timeout=30) as x:
- return json.loads(x.read().decode() or "{}")
- def main():
- if not MK and not DRY:
- sys.exit("PARSE_MASTER_KEY 未设置")
- arts = call("GET", "/classes/KfArtifact?limit=1000&order=createdAt")["results"]
- rep = next((a for a in arts if a.get("report") and a.get("ownerName") == REPORT_OWNER), None)
- if not rep:
- sys.exit("库里没有示例报告(先运行 tools/seed_report.py)")
- ins = next((i for i in call("GET", "/classes/KfInsight?limit=1000")["results"]
- if i.get("title") == INSIGHT_TITLE), None)
- if not ins:
- sys.exit(f"找不到归纳:{INSIGHT_TITLE}")
- derived = list(ins.get("derivedArtifacts") or ins.get("derivedFrom") or [])
- if rep["objectId"] not in derived:
- derived.append(rep["objectId"])
- body = {"derivedArtifacts": derived, "citedInsightIds": CONCL,
- "reportRoles": {rep["objectId"]: CONCL}}
- if DRY:
- print("[dry]", INSIGHT_TITLE, body)
- return
- r = call("PUT", f"/classes/KfInsight/{ins['objectId']}", body)
- print("insight linked:", ins["objectId"], "→", rep["objectId"], "| ok" if "updatedAt" in r else r)
- if __name__ == "__main__":
- main()
|