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

Function main

utils/update_scripts_list.py:144–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142
143
144def main():
145 # 自定义当前脚本列表使用的语言和文件
146 parser = argparse.ArgumentParser(description="更新脚本列表,并可指定语言")
147 parser.add_argument("--lang_code", default="zh-CN", help="语言代码")
148 parser.add_argument("--readme_path", default="docs/README.md", help="需要更新脚本列表的README 文件路径")
149 parser.add_argument("--json_file_path", default="docs/ScriptsPath.json", help="脚本列表的 JSON 文件路径")
150 args = parser.parse_args()
151 # 赋值全局变量
152 global LANG_CODE
153 LANG_CODE = args.lang_code
154 json_file_path = args.json_file_path
155 readme_path = args.readme_path
156 if is_file_updated_more_than(json_file_path, 5):
157 print("跳过文件 ,因为ScriptsPath.json在五分钟之内没有新提交。")
158 return
159 data = read_json(json_file_path)
160 sorted_scripts = sorted(data.get('scripts', []), key=lambda x: x['greasyfork_id'] if x.get('greasyfork_id') is not None else 0)
161 related_scripts_map = generate_description(sorted_scripts)
162 html_output = generate_grouped_html(related_scripts_map, False, False)
163 process_file(readme_path, html_output, "<!--AUTO_SCRIPTS_PLEASE_DONT_DELETE_IT-->", "<!--AUTO_SCRIPTS_PLEASE_DONT_DELETE_IT-END-->", "head")
164 scripts_count = len(data.get('scripts', []))
165 result = " | ".join(
166 f'<a href="#{related_id}-{len(scripts)}">'
167 f'{related_id} ({len(scripts)})</a>\n'
168 for related_id, scripts in related_scripts_map.items()
169 )
170 tip = f"**储存库当前发布脚本数量:{scripts_count},脚本包括:**\n<h6>{result}</h6>"
171 process_file(readme_path, tip, "<!--SCRIPTS_COUNT-->", "<!--SCRIPTS_COUNT-END-->", "head")
172
173
174if __name__ == "__main__":

Callers 1

Calls 6

read_jsonFunction · 0.90
process_fileFunction · 0.90
generate_grouped_htmlFunction · 0.85
getMethod · 0.80
generate_descriptionFunction · 0.70

Tested by

no test coverage detected