MCPcopy
hub / github.com/ChinaGodMan/UserScripts / go_work

Function go_work

utils/translate_chinese_to_filelang.py:32–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31# 遍历所有的脚本,投递任务进行翻译
32def go_work():
33 json_path = 'docs/ScriptsPath.json'
34 data = read_json(json_path)
35 scripts = data.get('scripts', [])
36 MAX_THREADS = 3 # 每次只允许操作三个文件,再大谷歌就限制请求了.
37 FILE_TIMEOUT = 30
38 GREEN = '\033[32m'
39 YELLOW = '\033[33m'
40 RESET = '\033[0m'
41 with ThreadPoolExecutor(max_workers=MAX_THREADS) as executor:
42 for script in scripts:
43 script_directory = script.get('directory', '')
44 md_files = get_md_files(script_directory)
45 TEMP_OUT = False
46 for file in md_files:
47 if file == 'README.md': # 直接退出,无需下面进行提取语言代码再退出.
48 continue
49 # 匹配 README_xx.md 格式的文件,并提取语言代码
50 lang_code = extract_lang_code(file)
51 if lang_code is None:
52 continue
53 if is_file_updated_more_than(f'{script_directory}/{file}', FILE_TIMEOUT):
54 continue
55 else:
56 if (not TEMP_OUT):
57 TEMP_OUT = True
58 print(f"正在处理脚本: {GREEN}{script.get('name', '')}{RESET} [{YELLOW}{script_directory}{RESET}]")
59 print(f"{YELLOW} ==>处理文件: [{script_directory}/{file}] |语言代码: {lang_code}{RESET}")
60 executor.submit(process_file, script_directory, file, lang_code)
61
62
63go_work()

Calls 5

read_jsonFunction · 0.90
get_md_filesFunction · 0.90
extract_lang_codeFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected