- 修改比分解析逻辑,只匹配破折号而不匹配冒号,避免将时间(19:00)误识别为比分 - 添加额外检查,确保不会将日期格式误识别为比分 - 添加TBD比赛保护机制,确保TBD vs TBD的比赛永远不会被标记为有比分或已完成 - 如果错误解析了TBD比赛的比分,会自动删除 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6fd21a64b9
commit
81eb9ba403
@ -165,14 +165,16 @@ class Dota2CalendarSync:
|
|||||||
# If score not found in structure, try text pattern
|
# If score not found in structure, try text pattern
|
||||||
if not has_score:
|
if not has_score:
|
||||||
text = parent.get_text()
|
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:
|
if score_pattern:
|
||||||
score1 = int(score_pattern.group(1))
|
score1 = int(score_pattern.group(1))
|
||||||
score2 = int(score_pattern.group(2))
|
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:
|
if 0 <= score1 <= 5 and 0 <= score2 <= 5 and (score1 + score2) > 0:
|
||||||
# Make sure it's not a time pattern (HH:MM)
|
# Additional check: make sure this isn't part of a date (e.g., 2025-01-14)
|
||||||
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]):
|
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
|
has_score = True
|
||||||
match_data['score'] = f"{score1}-{score2}"
|
match_data['score'] = f"{score1}-{score2}"
|
||||||
score_match = score_pattern
|
score_match = score_pattern
|
||||||
@ -219,43 +221,52 @@ class Dota2CalendarSync:
|
|||||||
|
|
||||||
# Mark if has score and if completed
|
# Mark if has score and if completed
|
||||||
if has_score:
|
if has_score:
|
||||||
# Score already set above, extract score values
|
# TBD vs TBD matches should NEVER be marked as having a score or completed
|
||||||
score_parts = re.match(r'(\d+)-(\d+)', match_data['score'])
|
if match_data.get('team1') == 'TBD' and match_data.get('team2') == 'TBD':
|
||||||
if score_parts:
|
has_score = False
|
||||||
score1 = int(score_parts.group(1))
|
match_data['completed'] = False
|
||||||
score2 = int(score_parts.group(2))
|
match_data['has_score'] = False
|
||||||
|
# Remove any incorrectly parsed score
|
||||||
|
if 'score' in match_data:
|
||||||
|
del match_data['score']
|
||||||
else:
|
else:
|
||||||
score1 = score2 = 0
|
# 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
|
# Check if series is actually completed based on format
|
||||||
series_completed = False
|
series_completed = False
|
||||||
if 'format' in match_data:
|
if 'format' in match_data:
|
||||||
if 'Bo3' in match_data['format']:
|
if 'Bo3' in match_data['format']:
|
||||||
# Bo3 is complete when someone reaches 2 wins
|
# 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)
|
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['completed'] = series_completed
|
||||||
match_data['has_score'] = True # Mark that there's a score even if not completed
|
match_data['has_score'] = True # Mark that there's a score even if not completed
|
||||||
|
|
||||||
# Determine winner only if completed
|
# Determine winner only if completed
|
||||||
if series_completed:
|
if series_completed:
|
||||||
if score1 > score2:
|
if score1 > score2:
|
||||||
match_data['winner'] = match_data.get('team1', 'Unknown')
|
match_data['winner'] = match_data.get('team1', 'Unknown')
|
||||||
else:
|
else:
|
||||||
match_data['winner'] = match_data.get('team2', 'Unknown')
|
match_data['winner'] = match_data.get('team2', 'Unknown')
|
||||||
else:
|
else:
|
||||||
match_data['completed'] = False
|
match_data['completed'] = False
|
||||||
match_data['has_score'] = False
|
match_data['has_score'] = False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user