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