diff --git a/sync_status_readme.py b/sync_status_readme.py index 0be0209..4b2fb90 100644 --- a/sync_status_readme.py +++ b/sync_status_readme.py @@ -407,29 +407,31 @@ def main(): stats_content += f"- Fork人数: {stats['fork_count']}\n" # 将统计数据添加到文件末尾 # 在标记后插入统计数据 - # 检查是否已存在统计数据 - stats_start = new_content.find("\n## 统计数据\n") - if stats_start != -1: - # 如果存在,替换现有的统计数据 - stats_end = new_content.find("\n##", stats_start + 1) - if stats_end == -1: - stats_end = len(new_content) - new_content = new_content[:stats_start] + \ - stats_content + new_content[stats_end:] + stats_start = new_content.find( + "") + stats_end = new_content.find("") + + if stats_start != -1 and stats_end != -1: + # Replace existing statistical data + new_content = new_content[:stats_start] + "\n" + stats_content + \ + "" + \ + new_content[stats_end + + len(""):] else: - # 如果不存在,在标记后插入统计数据 + # Add new statistical data after end_table_marker = "" end_table_index = new_content.find(end_table_marker) if end_table_index != -1: insert_position = end_table_index + \ len(end_table_marker) - new_content = new_content[:insert_position] + \ - "\n" + stats_content + \ + new_content = new_content[:insert_position] + "\n\n\n" + \ + stats_content + "" + \ new_content[insert_position:] else: logging.warning( " marker not found. Appending stats to the end.") - new_content += "\n" + stats_content + new_content += "\n\n\n" + \ + stats_content + "" with open(README_FILE, 'w', encoding='utf-8') as file: file.write(new_content) logging.info("README.md has been successfully updated.")