"""Render structured meeting notes to Markdown or a Word document."""
import argparse
import json
from pathlib import Path
import sys
def content(data):
topic = data.get("topic")
date = data.get("date")
if not all(isinstance(x,str) and x.strip() for x in (topic,date)):
raise ValueError("topic and date are required strings")
groups = {}
for label in ("participants","discussion","decisions"):
items=data.get(label)
if not isinstance(items,list) or not all(isinstance(x,str) and x.strip() for x in items):
raise ValueError(f"{label} must contain strings")
groups[label]=items
actions=data.get("actions")
if not isinstance(actions,list):
raise ValueError("actions must be a list")
action_lines=[]
for row in actions:
if not isinstance(row,dict) or not all(isinstance(row.get(k),str) and row[k].strip()
for k in ("task","owner","due")):
raise ValueError("each action needs task, owner and due")
action_lines.append(f"{row['task']} | {row['owner']} | {row['due']}")
return topic, [("Meeting information",[date,", ".join(groups["participants"])]),
("Discussion",groups["discussion"]),("Decisions",groups["decisions"]),("Actions",action_lines)]
def render(topic, sections, target):
if target.suffix.lower()==".docx":
from docx import Document
doc=Document()
doc.add_heading(topic,0)
for title,items in sections:
doc.add_heading(title,1)
for value in items:
doc.add_paragraph(value)
doc.save(target)
elif target.suffix.lower()==".md":
parts=[f"# {topic}"]
parts.extend("\n".join([f"## {title}",*(f"- {item}" for item in items)]) for title,items in sections)
target.write_text("\n\n".join(parts)+"\n",encoding="utf8")
else:
raise ValueError("output must end in .md or .docx")
def main(argv=None):
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument("source", type=Path)
parser.add_argument("target", type=Path)
parser.add_argument("--debug", action="store_true")
args=parser.parse_args(argv)
try:
raw=args.source.read_bytes()
meeting=json.loads(raw)
if not isinstance(meeting,dict):
raise ValueError("input must be an object")
topic, sections=content(meeting)
if args.debug:
print(f"[debug] source={args.source.name} format={args.target.suffix} input_bytes={len(raw)} "
f"actions={len(sections[-1][1])}",file=sys.stderr)
render(topic,sections,args.target)
except ValueError as error:
print(f"invalid input or format: {error}",file=sys.stderr)
return 2
except FileNotFoundError:
print("input or output directory not found",file=sys.stderr)
return 3
except PermissionError:
print("unable to write or read the requested path",file=sys.stderr)
return 4
except ModuleNotFoundError:
print("use the declared python-docx dependency for Word output",file=sys.stderr)
return 5
print(json.dumps({"output_file":args.target.name, "actions":len(sections[-1][1])}))
return 0
if __name__=="__main__":
raise SystemExit(main())
本例需在 Windows、Python 3.12。各实验所需工具和版本见下载包 README。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows、Python 3.12。各实验所需工具和版本见下载包 README。
入口文件:projects/skills-creator/workshop-minutes/scripts/minutes.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
minutes.py,或下载右侧课程工程包。 - 确认本地已准备 Windows、Python 3.12。各实验所需工具和版本见下载包 README。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联2章) · 含当前章节或实例 · mbskycom202612a334.zip
课程关联工程包(登记关联39章) · 含当前章节或实例 · mbskycom202612a331.zip