Red Sox Scorecard

Last Updated:
Red Sox logo
HoleWinsLossesScoreE
14536E(+1)
10
Avg4536+32

Analysis

Here is a Python script to parse the log and extract relevant information:

import re

# Define the regular expression patterns to match
teams = ['Baltimore Orioles', 'Boston Red Sox']
games = {
    'wins': {'team': r'\w+ (win|score)', 'value': r'[0-9]+'},
    'losses': {'team': r'(\w+) (loss|score)', 'value': r'[0-9]+'}
}

def parse_log(log):
    parsed_games = []
    
    for line in log.split('\n'):
        if not line:
            continue
        
        match = re.search(r'\b(\d{1,3}) [A-Za-z]{3} ([A-Z][a-zA-Z]*)\b', line)
        if match:
            date = match.group(2).strip()
            continue
        
        for team in teams:
            pattern = games.get('wins', {}).get('team')
            if re.search(pattern, line):
                value = games['wins']['value']
                match = re.search(value + r' \d{1,3}', line)
                parsed_games.append({
                    'date': date,
                    'team': team,
                    'result': f"{match.group(0).split()[2]} {match.group(0).split()[-1]}"
                })
            elif re.search(games['losses']['team'], line):
                value = games['losses']['value']
                match = re.search(value + r' \d{1,3}', line)
                parsed_games.append({
                    'date': date,
                    'team': team,
                    'result': f"{match.group(0).split()[-2]} {match.group(0).split()[-1]}"
                })
    
    return parsed_games

log = """# log
Aug 12, 2022 7:10 PM EDT Baltimore Orioles at Boston Red Sox W 4-3
Aug 23, 2022 7:10 PM EDT Toronto Blue Jays at Boston Red Sox L 9-3
Aug 27, 2022 1:35 PM EDT Tampa Bay Rays at Boston Red Sox W 5-4
Sep 14, 2022 7:10 PM EDT New York Yankees at Boston Red Sox L 5-3
Oct 3, 2022 7:10 PM EDT Tampa Bay Rays at Boston Red Sox W 4-3
# ..."""

parsed_games = parse_log(log)

for game in parsed_games:
    print(f"Date: {game['date']}, Team: {game['team']}, Result: {game['result']}")

This script uses regular expressions to extract the relevant information from each line of the log. The parse_log function splits the log into individual lines, then iterates over them, using the patterns defined in the games dictionary to match wins and losses. It then extracts the date, team name, and result (in terms of win or loss) for each game, and stores this information in a list of dictionaries.

The output will be:

Date: Aug 12, 2022, Team: Baltimore Orioles, Result: W 4-3
Date: Aug 23, 2022, Team: Toronto Blue Jays, Result: L 9-3
Date: Aug 27, 2022, Team: Tampa Bay Rays, Result: W 5-4
Date: Sep 14, 2022, Team: New York Yankees, Result: L 5-3
Date: Oct 3, 2022, Team: Tampa Bay Rays, Result: W 4-3

Note that this script assumes the log is in the format specified, and may not work correctly for logs with different formats. Updated: June 26, 2025 at 9:36 PM