diff --git a/sync_status_readme.py b/sync_status_readme.py index 0a69c1d..6dc6e0c 100644 --- a/sync_status_readme.py +++ b/sync_status_readme.py @@ -12,9 +12,9 @@ END_DATE = datetime.fromisoformat(os.environ.get( 'END_DATE', '2024-07-14T23:59:59+00:00')).replace(tzinfo=pytz.UTC) DEFAULT_TIMEZONE = 'Asia/Shanghai' -FILE_SUFFIX = os.environ.get('FILE_SUFFIX', '_EICL1st.md') +FILE_SUFFIX = os.environ.get('FILE_SUFFIX', '.md') README_FILE = 'README.md' -FIELD_NAME = os.environ.get('FIELD_NAME', 'EICL1st· Name') +FIELD_NAME = os.environ.get('FIELD_NAME', 'Name') Content_START_MARKER = "" Content_END_MARKER = "" TABLE_START_MARKER = "" @@ -198,8 +198,10 @@ def check_weekly_status(user_status, date, user_tz): def get_all_user_files(): + exclude_prefixes = ('template', 'readme') return [f[:-len(FILE_SUFFIX)] for f in os.listdir('.') - if f.endswith(FILE_SUFFIX) and not f.startswith('Template')] + if f.lower().endswith(FILE_SUFFIX.lower()) + and not f.lower().startswith(exclude_prefixes)] def update_readme(content): @@ -349,6 +351,7 @@ def calculate_statistics(content): eliminated_participants = 0 completed_participants = 0 perfect_attendance_users = [] + completed_users = [] for row in rows: user_name = row.split('|')[1].strip() @@ -359,9 +362,11 @@ def calculate_statistics(content): eliminated_participants += 1 elif all(status == '✅' for status in statuses): completed_participants += 1 + completed_users.append(user_name) perfect_attendance_users.append(user_name) elif all(status in ['✅', '⭕️', ' '] for status in statuses): completed_participants += 1 + completed_users.append(user_name) elimination_rate = (eliminated_participants / total_participants) * 100 if total_participants > 0 else 0 @@ -373,7 +378,8 @@ def calculate_statistics(content): 'eliminated_participants': eliminated_participants, 'elimination_rate': elimination_rate, 'fork_count': fork_count, - 'perfect_attendance_users': perfect_attendance_users + 'perfect_attendance_users': perfect_attendance_users, + 'completed_users': completed_users } @@ -401,35 +407,38 @@ def main(): stats_content = f"\n\n## 统计数据\n\n" stats_content += f"- 总参与人数: {stats['total_participants']}\n" stats_content += f"- 完成人数: {stats['completed_participants']}\n" + stats_content += f"- 完成用户: {', '.join(stats['completed_users'])}\n" stats_content += f"- 全勤用户: {', '.join(stats['perfect_attendance_users'])}\n" stats_content += f"- 淘汰人数: {stats['eliminated_participants']}\n" stats_content += f"- 淘汰率: {stats['elimination_rate']:.2f}%\n" 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.")