Skill-BidCreater/scripts/docx_patch.py
2026-03-14 08:49:28 +08:00

28 lines
937 B
Python

from __future__ import annotations
import argparse
from pathlib import Path
from docx_ops_lib import apply_patch_document, read_json, render_docx, write_json
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--patch-file", required=True)
parser.add_argument("--report", required=True)
parser.add_argument("--render-check", action="store_true")
parser.add_argument("--render-dir")
args = parser.parse_args()
patch_data = read_json(Path(args.patch_file).resolve())
report = apply_patch_document(patch_data)
if args.render_check:
output_docx = Path(report["output_docx"]).resolve()
render_dir = Path(args.render_dir).resolve() if args.render_dir else output_docx.parent / f"{output_docx.stem}_render"
report["render"] = render_docx(output_docx, render_dir)
write_json(Path(args.report).resolve(), report)
if __name__ == "__main__":
main()