蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

验证会议纪要的决议、负责人和截止日期

PYTHONPython 3.12,独立目录,标准库。evaluate_minutes.py
evaluate_minutes.py76 行
from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZIP_DEFLATED, ZipFile
import json

ROOT = Path(__file__).resolve().parent
SKILL = ROOT / "station-minutes"


def fields(transcript):
    labels = {}
    actions = []
    for line in transcript.splitlines():
        key, value = line.split(":", 1)
        if key == "行动":
            actions.append(value.split("|"))
        else:
            labels[key] = value
    return labels, actions


def render(labels, actions, template=None):
    headings = list(labels) + ["下一步行动"]
    if template is not None:
        headings = [line.removeprefix("# ") for line in template.splitlines()]
    output = []
    for heading in headings:
        output.append("# " + heading)
        if heading == "下一步行动":
            for task, owner, due in actions:
                output.append(f"- {task}|{owner}|{due or '待确认'}" if template else "- " + task)
        else:
            output.append(labels[heading])
    return "\n".join(output) + "\n"


def grade(text):
    return {
        "decision": "# 决议事项\n先更换北门标识。" in text,
        "owner_and_due": "更换标识|柳青|2027-04-16" in text,
        "unknown_due": "复测夜间辨识度|丁河|待确认" in text,
    }


def package(destination):
    document = (SKILL / "SKILL.md").read_text(encoding="utf-8")
    _, metadata, body = document.split("---", 2)
    header = dict(line.split(": ", 1) for line in metadata.strip().splitlines())
    if header["name"] != SKILL.name or not header["description"] or not body.strip():
        raise ValueError("Missing skill name, description or instructions.")
    with ZipFile(destination, mode="w", compression=ZIP_DEFLATED) as archive:
        for path in sorted(p for p in SKILL.rglob("*") if p.is_file()):
            archive.write(path, path.relative_to(SKILL.parent).as_posix())


def main():
    labels, actions = fields((ROOT / "transcript.txt").read_text(encoding="utf-8"))
    template_path = SKILL / "references/minutes-template.md"
    baseline = render(labels, actions)
    guided = render(labels, actions, template_path.read_text(encoding="utf-8"))
    with TemporaryDirectory(prefix="minutes-") as tmp:
        path = Path(tmp) / "station-minutes.skill"
        package(path)
        with ZipFile(BytesIO(path.read_bytes())) as archive:
            entries = sorted(archive.namelist())
            archive_valid = archive.testzip() is None
            same_template = archive.read("station-minutes/references/minutes-template.md") == template_path.read_bytes()
    print(json.dumps(dict(baseline=grade(baseline), guided=grade(guided), guided_markdown=guided,
                          package_entries=entries, archive_valid=archive_valid,
                          same_template=same_template), ensure_ascii=False))


if __name__ == "__main__":
    main()
本例需在 Python 3.12,独立目录,标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Python 3.12,独立目录,标准库。

入口文件:projects/claude-code-creator/evaluate_minutes.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 evaluate_minutes.py,或下载右侧课程工程包。
  2. 确认本地已准备 Python 3.12,独立目录,标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Claude Code

课程关联工程包(登记关联42章) · 含当前章节或实例 · mbskycom202612a3117.zip

下载课程关联工程包:Claude Code

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3143.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习