大须大镜 | Mayahilwa Mayakimhemot/ toolbox/ 目度 Systemedo

【蜷荷音序基字表】荷基字堆砌表(拉丁正字顺序)

tool python

按音序生成蜷文部分的基字表,用于在FontCreator中检阅荷Hahabot字体。

Python解译器代码

# 定义python文件路径
with open(r'------\【蜷荷音序基字表】荷基字堆砌表(拉丁正字顺序).py', 'r', encoding='utf-8') as file:
    code = file.read()
exec(code)

【蜷荷音序基字表】荷基字堆砌表(拉丁正字顺序).py

import os

# 定义词典文件夹路径'dictionary_folder'
dictionary_folder = r'------'

# 读取词典中的单词和含义
def read_dictionary(folder_path):
    dictionary = {}
    for filename in os.listdir(folder_path):
        if filename.endswith('.md'):
            if '%' in filename:
                parts = filename[:-3].split('%')
                # 确保文件名格式正确
                if len(parts) == 2:
                    word, meaning = parts
                    # 如果含义已经存在于字典中,则将词条添加到已有的词条后面
                    if meaning in dictionary:
                        dictionary[meaning] += '/' + word
                    else:
                        dictionary[meaning] = word
    return dictionary

# 递归读取词典中的单词和含义,包括子文件夹
def read_dictionary_recursive(folder_path):
    dictionary = read_dictionary(folder_path)
    for entry in os.scandir(folder_path):
        if entry.is_dir():  # 如果是文件夹,则递归调用
            nested_dict = read_dictionary_recursive(entry.path)
            for meaning, words in nested_dict.items():
                if meaning in dictionary:
                    dictionary[meaning] += '/' + words
                else:
                    dictionary[meaning] = words
    return dictionary

# 主函数
def main():
    try:
        # 标记Kubcqesot版本
        kubcqesot_version = input('Kubcqesot 版本号:')
        cqosläpela_version = input('Cqosläpela 版本号:')
        # 读取字典(仅蜷文)
        dictionary = read_dictionary_recursive(dictionary_folder)
        # 初始化基字表
        base_glyphs = []
        # 设置基字表表头
        base_glyphs.append(f'Kubcqesot Dictionary\n===\nversion: K{kubcqesot_version} C{cqosläpela_version}\n---\n```\n')
        # 排序
        sorted_dictionary = sorted(dictionary.items(), key=lambda item: item[1])
        # 处理词典,编写基字表
        for meaning, words in sorted_dictionary:
            if meaning not in base_glyphs:
                base_glyphs.append(meaning)
        # 完成表尾
        base_glyphs.append('\n```')
        # 完成基字表
        base_table= ''.join(base_glyphs)
        # 打印测试
        print(base_table)
        # 确认保存路径
        # 定义保存路径
        output_path = f'------\\'
        os.makedirs(os.path.dirname(output_path), exist_ok=True)
        # 保存为Markdown文件
        # 定义保存名称
        output_file = f'------\\【音序基字表】蜷荷 K{kubcqesot_version} C{cqosläpela_version}.md'
        with open(output_file, "w", encoding="utf-8") as f:
            print(f"正在将音序基字表K{kubcqesot_version} C{cqosläpela_version}保存到{output_file}")
            f.write(base_table)
            print('保存完成')
    except Exception as e:
        print(f"发生错误:{e}")
        input("按 Enter 键退出...")

if __name__ == "__main__":
    main()