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

Function generate_description

utils/update_related_scripts.py:11–41  ·  view source on GitHub ↗
(current_group, all_scripts, lang)

Source from the content-addressed store, hash-verified

9
10# 生成描述信息,仅针对当前脚本的gro
11def generate_description(current_group, all_scripts, lang):
12 descriptions = []
13 # 如果没有 current_group,返回空描述
14 if not current_group:
15 return "无相关脚本。\n\n"
16 # 添加分类名到描述中
17 descriptions.append(
18 f'<img height="6px" width="100%" '
19 'src="{separator}">\n\n'
20 f'> ### 🔍你可能在找{current_group}\n>')
21 # id升序
22 sorted_scripts = sorted(all_scripts, key=lambda x: x['greasyfork_id'] if x.get('greasyfork_id') is not None else 0)
23 # 遍历所有脚本,查找具有相同 group 值的脚本
24 for script in sorted_scripts:
25 script_group = script.get('group')
26 # 如果脚本的 relatedscripts 与当前脚本相同,就将其添加到描述中
27 if script_group == current_group:
28 greasyfork_id = script.get('greasyfork_id')
29 full_path = script.get('directory') + "/" + script.get('js_name')
30 results = search_in_file(full_path, lang)
31 name = results.name_matches[0]
32 description = results.description_matches[0]
33 # 导入失败的脚本没有id直接使用github
34 if greasyfork_id in (None, 0):
35 item = f"[**{name}**](https://github.com/{get_repo_name()}/tree/main/{script.get('directory')}#readme)"
36 else:
37 item = f"[**{name}**](https://greasyfork.org/scripts/{greasyfork_id})"
38
39 descriptions.append(f"> - {item}: {description}")
40 str = format_str("\n".join(descriptions) + "\n")
41 return str
42
43
44def process_script(script, scripts, start_tag, end_tag, group):

Callers 1

process_scriptFunction · 0.70

Calls 4

search_in_fileFunction · 0.90
get_repo_nameFunction · 0.90
format_strFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected