()
| 81 | |
| 82 | |
| 83 | def main(): |
| 84 | parser = argparse.ArgumentParser(description="从指定文件读取脚本编号并输出脚本信息") |
| 85 | parser.add_argument( |
| 86 | "-i", "--input", required=True, help="输入文件路径,每行一个脚本编号" |
| 87 | ) |
| 88 | |
| 89 | args = parser.parse_args() |
| 90 | script_directory = args.input |
| 91 | authors_file = script_directory + '/AUTHORS.md' |
| 92 | start_tag = "<!--AUTHORS-->" |
| 93 | end_tag = "<!--AUTHORS-END-->" |
| 94 | |
| 95 | # 文件不存在直接结束 |
| 96 | if not os.path.exists(authors_file): |
| 97 | sys.exit() |
| 98 | |
| 99 | # 跳过未变动文件 |
| 100 | if is_file_updated_more_than(authors_file, 5): |
| 101 | sys.exit() |
| 102 | |
| 103 | # 生产最新的内容 |
| 104 | result_text = process_script_ids(authors_file) |
| 105 | others = get_file_description(authors_file, '<!--OTHERS-->', '<!--OTHERS-END-->') |
| 106 | |
| 107 | # 构建的greasyfork网站的链接和其他引用信息都为空. |
| 108 | if not result_text and not others: |
| 109 | print(f' ==> \033[38;2;255;0;0m[{authors_file}] 没有内容\033[0m') |
| 110 | sys.exit() |
| 111 | |
| 112 | scripts_link = '## 💖 脚本参考或使用了以下脚本:\n' + result_text |
| 113 | |
| 114 | # 写出到`authors_file` |
| 115 | process_file_plus(authors_file, scripts_link, start_tag, end_tag, "<!--HISTORY-END-->", "below") |
| 116 | |
| 117 | # greasyfork的链接和其他引用拼接起来 |
| 118 | if others: |
| 119 | # 没有greasyfrok的链接,不添加换行符 |
| 120 | scripts_link += f'<br>\n{others}' if result_text else others |
| 121 | |
| 122 | old_scripts_link = get_file_description(script_directory + '/README.md', start_tag, end_tag) |
| 123 | |
| 124 | # 新的脚本链接和旧的脚本链接一样,也不用更新. |
| 125 | if scripts_link == old_scripts_link: |
| 126 | print(f' ==> \033[38;2;255;0;0m[{script_directory}/README.md] 描述未变化\033[0m') |
| 127 | else: |
| 128 | md_files = get_md_files(script_directory) |
| 129 | for md_file in md_files: |
| 130 | file_path = os.path.join(script_directory, md_file) |
| 131 | process_file_plus(file_path, scripts_link, start_tag, end_tag, "<!--HISTORY-END-->", "below") |
| 132 | |
| 133 | |
| 134 | if __name__ == "__main__": |
no test coverage detected