From afa958731c0e8264ba8da51ab640d9bf315dfa20 Mon Sep 17 00:00:00 2001 From: SkyEye_FAST Date: Mon, 19 Aug 2024 00:34:52 +0800 Subject: [PATCH] Update --- base.py | 5 +++-- converter.py | 4 ++-- requirements.txt | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/base.py b/base.py index 6b13215..edb780f 100644 --- a/base.py +++ b/base.py @@ -1,10 +1,11 @@ # -*- encoding: utf-8 -*- """基础文件""" -import json from pathlib import Path from typing import TypeAlias, Dict, Set, Tuple +import ujson + # 当前绝对路径 P = Path(__file__).resolve().parent @@ -25,7 +26,7 @@ def load_json(file: str, folder: str = "data") -> Ldata: """ with open(P / folder / f"{file}.json", "r", encoding="utf-8") as f: - return json.load(f) + return ujson.load(f) def file_size(p: Path): diff --git a/converter.py b/converter.py index 9cddb98..678d822 100644 --- a/converter.py +++ b/converter.py @@ -1,12 +1,12 @@ # -*- encoding: utf-8 -*- """难视语言转换器""" -import json import re import time import inspect from typing import List, Set, Tuple, Callable, Optional +import ujson from romajitable import to_kana as tk from pypinyin import Style, lazy_pinyin, load_phrases_dict from pypinyin_dict.phrase_pinyin_data import cc_cedict, di @@ -432,6 +432,6 @@ def save_to_json( input_dict, elapsed_time = input_data file_path = P / output_folder / f"{output_file}.json" with open(file_path, "w", encoding="utf-8") as j: - json.dump(input_dict, j, indent=2, ensure_ascii=False) + ujson.dump(input_dict, j, indent=2, ensure_ascii=False) size = file_size(file_path) print(f"已生成语言文件“{output_file}.json”,大小{size},耗时{elapsed_time:.2f} s。") diff --git a/requirements.txt b/requirements.txt index b565cc8..8950f9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,6 @@ jieba>=0.42.1 pypinyin>=0.52.0 pypinyin_dict>=0.8.0 Requests>=2.32.3 +rich>=13.7.1 romajitable>=0.0.1 -opencc >= 1.1.9 \ No newline at end of file +ujson>=5.10.0 \ No newline at end of file