Blame view

ExportFiles/merge_mcp_tech_kjb_detail_json.py 1.05 KB
db9c79c0   “wangming”   feat: punch-based...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  # -*- coding: utf-8 -*-
  """合并 MCP 两次查询的 JSON 数组,供 _generate_mcp_tech_kjb_detail_excel.py 使用。
  
  示例(开单、退卡各保存为一个 JSON 数组文件):
    python3 merge_mcp_tech_kjb_detail_json.py open.json refund.json _mcp_tech_kjb_detail_202603.json
  """
  import json
  import sys
  from pathlib import Path
  
  
  def main():
      if len(sys.argv) != 4:
          print(
              "Usage: merge_mcp_tech_kjb_detail_json.py <开单.json> <退卡.json> <输出.json>",
              file=sys.stderr,
          )
          sys.exit(1)
      open_path, refund_path, out_path = Path(sys.argv[1]), Path(sys.argv[2]), Path(sys.argv[3])
      a = json.loads(open_path.read_text(encoding="utf-8"))
      b = json.loads(refund_path.read_text(encoding="utf-8"))
      if not isinstance(a, list) or not isinstance(b, list):
          sys.exit("输入文件须为 JSON 数组")
      merged = a + b
      out_path.write_text(json.dumps(merged, ensure_ascii=False, indent=2), encoding="utf-8")
      print("Wrote", out_path, "rows:", len(merged))
  
  
  if __name__ == "__main__":
      main()