From 81eb9ba403ddf07ccfade3d55f938166e7dce968 Mon Sep 17 00:00:00 2001 From: Ching Date: Sun, 7 Sep 2025 11:57:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTBD=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=A0=87=E8=AE=B0=E4=B8=BA=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改比分解析逻辑,只匹配破折号而不匹配冒号,避免将时间(19:00)误识别为比分 - 添加额外检查,确保不会将日期格式误识别为比分 - 添加TBD比赛保护机制,确保TBD vs TBD的比赛永远不会被标记为有比分或已完成 - 如果错误解析了TBD比赛的比分,会自动删除 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- sync_dota2_matches.py | 89 ++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/sync_dota2_matches.py b/sync_dota2_matches.py index 35b4463..e8b4c23 100644 --- a/sync_dota2_matches.py +++ b/sync_dota2_matches.py @@ -165,14 +165,16 @@ class Dota2CalendarSync: # If score not found in structure, try text pattern if not has_score: text = parent.get_text() - score_pattern = re.search(r'(\d{1,2})[:|-](\d{1,2})', text) + # Only look for dash pattern (not colon) to avoid matching time + score_pattern = re.search(r'(\d{1,2})-(\d{1,2})', text) if score_pattern: score1 = int(score_pattern.group(1)) score2 = int(score_pattern.group(2)) - # Validate it's a reasonable game score and not time + # Validate it's a reasonable game score if 0 <= score1 <= 5 and 0 <= score2 <= 5 and (score1 + score2) > 0: - # Make sure it's not a time pattern (HH:MM) - if not re.search(r'\d{1,2}:\d{2}\s*(?:CEST?|UTC|[AP]M)', text[max(0, score_pattern.start()-10):score_pattern.end()+10]): + # Additional check: make sure this isn't part of a date (e.g., 2025-01-14) + surrounding_text = text[max(0, score_pattern.start()-5):score_pattern.end()+5] + if not re.search(r'\d{4}-\d{1,2}-\d{1,2}', surrounding_text): has_score = True match_data['score'] = f"{score1}-{score2}" score_match = score_pattern @@ -219,43 +221,52 @@ class Dota2CalendarSync: # Mark if has score and if completed if has_score: - # Score already set above, extract score values - score_parts = re.match(r'(\d+)-(\d+)', match_data['score']) - if score_parts: - score1 = int(score_parts.group(1)) - score2 = int(score_parts.group(2)) + # TBD vs TBD matches should NEVER be marked as having a score or completed + if match_data.get('team1') == 'TBD' and match_data.get('team2') == 'TBD': + has_score = False + match_data['completed'] = False + match_data['has_score'] = False + # Remove any incorrectly parsed score + if 'score' in match_data: + del match_data['score'] else: - score1 = score2 = 0 - - # Check if series is actually completed based on format - series_completed = False - if 'format' in match_data: - if 'Bo3' in match_data['format']: - # Bo3 is complete when someone reaches 2 wins + # Score already set above, extract score values + score_parts = re.match(r'(\d+)-(\d+)', match_data['score']) + if score_parts: + score1 = int(score_parts.group(1)) + score2 = int(score_parts.group(2)) + else: + score1 = score2 = 0 + + # Check if series is actually completed based on format + series_completed = False + if 'format' in match_data: + if 'Bo3' in match_data['format']: + # Bo3 is complete when someone reaches 2 wins + series_completed = (score1 >= 2 or score2 >= 2) + elif 'Bo5' in match_data['format']: + # Bo5 is complete when someone reaches 3 wins + series_completed = (score1 >= 3 or score2 >= 3) + elif 'Bo1' in match_data['format']: + # Bo1 is complete when there's any score + series_completed = True + else: + # Unknown format, assume completed if there's a score + series_completed = True + else: + # No format info, try to guess from score + # If someone has 2+ wins, likely a completed Bo3/Bo5 series_completed = (score1 >= 2 or score2 >= 2) - elif 'Bo5' in match_data['format']: - # Bo5 is complete when someone reaches 3 wins - series_completed = (score1 >= 3 or score2 >= 3) - elif 'Bo1' in match_data['format']: - # Bo1 is complete when there's any score - series_completed = True - else: - # Unknown format, assume completed if there's a score - series_completed = True - else: - # No format info, try to guess from score - # If someone has 2+ wins, likely a completed Bo3/Bo5 - series_completed = (score1 >= 2 or score2 >= 2) - - match_data['completed'] = series_completed - match_data['has_score'] = True # Mark that there's a score even if not completed - - # Determine winner only if completed - if series_completed: - if score1 > score2: - match_data['winner'] = match_data.get('team1', 'Unknown') - else: - match_data['winner'] = match_data.get('team2', 'Unknown') + + match_data['completed'] = series_completed + match_data['has_score'] = True # Mark that there's a score even if not completed + + # Determine winner only if completed + if series_completed: + if score1 > score2: + match_data['winner'] = match_data.get('team1', 'Unknown') + else: + match_data['winner'] = match_data.get('team2', 'Unknown') else: match_data['completed'] = False match_data['has_score'] = False