PRA-only-demo/scripts/gen-word-flow.py
yu 230e3c79ec docs: 平台标记单一源规则与迁移指南通俗版;补交 Word 报告流程生成脚本
- dev-conventions:平台标记收敛为注册分组表单一源,能力文件不得散写 process.platform
- rpa-core-migration-guide:重写为通俗版(现状/搬迁步骤/三端计划)
- gen-word-flow.py:Word 报告加工流程生成脚本(此前漏交)
2026-11-05 17:02:10 +08:00

87 lines
3.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""生成「Word 报告加工」测试流程:打开比价报告 -> 读全文 -> 查找替换 -> 追加加工说明 -> 插入截图 -> 复制副本 -> 弹窗"""
import json
import os
DESK = "C:/Users/Administrator/Desktop"
SRC = f"{DESK}/淘宝手机比价报告.docx"
SHOT = f"{DESK}/RPA整理测试/整理完成截图.png"
nodes = []
edges = []
def node(nid, comp, label, values, x=300, y=0, output=None, options=None):
n = {
"id": nid,
"componentId": comp,
"label": label,
"values": values,
"position": {"x": x, "y": y},
}
if output:
n["options"] = dict(options or {}, outputVar=output)
elif options:
n["options"] = options
nodes.append(n)
return nid
def link(a, b):
edges.append({"id": f"edge_{a}_{b}", "source": a, "target": b})
seq = []
node("node_start", "Trigger.Manual", "触发·立即执行", {"entryName": "立即执行"}, 240, 70, options={"timeoutMs": 30000})
seq.append("node_start")
y = 160
nid = node("node_open", "Word_Open", "打开比价报告", {"filePath": SRC}, 300, y, output="wordDoc")
seq.append(nid); y += 160
nid = node("node_read", "Word_ReadAll", "读取报告全文", {"objWord": "${wordDoc}"}, 300, y, output="docText")
seq.append(nid); y += 160
nid = node("node_replace", "Word_Replace", "替换标注校验状态",
{"objWord": "${wordDoc}", "oldText": "RPA 自动采集", "newText": "RPA 自动采集(已加工校验)"}, 300, y)
seq.append(nid); y += 160
nid = node("node_enter", "Word_Enter", "文末空行", {"objWord": "${wordDoc}"}, 300, y)
seq.append(nid); y += 160
nid = node("node_write", "Word_Write", "追加加工说明",
{"objWord": "${wordDoc}",
"text": "—— RPA 加工记录:本报告全文 ${len(docText)} 字,已由晨间自动化流程于今日读取校验,并在文末插入整理完成截图。"},
300, y)
seq.append(nid); y += 160
nid = node("node_pic", "Word_InsertPicture", "文末插入整理截图",
{"objWord": "${wordDoc}", "imageaddr": SHOT}, 300, y)
seq.append(nid); y += 160
nid = node("node_save", "Word_Save", "保存修改", {"objWord": "${wordDoc}"}, 300, y)
seq.append(nid); y += 160
nid = node("node_copy", "File_Copy_V1", "复制生成加工版副本",
{"file_type": "file", "file_path": SRC, "folder_path": DESK, "target_path": DESK,
"rename": "1", "name": "淘宝手机比价报告_加工版.docx", "action": "覆盖"}, 300, y)
seq.append(nid); y += 160
nid = node("node_close", "Word_Close", "关闭文档", {"objWord": "${wordDoc}", "isKill": "0"}, 300, y)
seq.append(nid); y += 160
nid = node("node_notice", "Dialog_Notice_V2", "完成通知",
{"text": "Word 报告加工完成:已替换标注、追加说明、插入截图,副本存桌面《淘宝手机比价报告_加工版.docx》",
"title": "加工完成", "time_out": "10"}, 300, y)
seq.append(nid)
for i in range(len(seq) - 1):
link(seq[i], seq[i + 1])
flow = {"id": "flow_word_report_process", "name": "Word 报告加工", "nodes": nodes, "edges": edges, "variables": []}
out = os.path.join(os.environ["APPDATA"], "rpa-studio", "flows", "flow_word_report_process.json")
with open(out, "w", encoding="utf-8") as f:
json.dump(flow, f, ensure_ascii=False, indent=2)
print("written:", out, f"nodes={len(nodes)} edges={len(edges)}")