Files
baseball-db/src/apps/generate/calendar.py
Anthony Correa 2a521e9016 Update calendar generation and data normalization; add read check command
- Add config file support for calendar colors and logos in generate_calendar
- Extend normalization mappings in normalization.toml for fields and teams
- Add 'read check' command to summarize game and field data from input files
- Fix normalization to correctly handle visitor field and value lookups
- Update launch configurations for new data and options
2025-08-26 16:42:19 -05:00

55 lines
2.0 KiB
Python

import typer
from rich.console import Console
from typing import Annotated, List, Optional
from pathlib import Path
from ...utils.sportspress import validate_keys
from ...utils.normalize import normalize_header_key, load_config
from ...utils.common import read_and_normalize_csv_or_xlsx, is_visitor_home_order_reversed, import_gamebygame, parse_datetime, personalize_data_for_team
from ...utils.sportspress import write_sportspress_csv
from .calendar_utils import generate_calendar
from collections import defaultdict
import toml
app = typer.Typer()
@app.command(name="calendar")
def generate_calendar_app(
input_file: Annotated[List[Path], typer.Argument(..., help="Path(s) to the CSV file")],
config_file: Annotated[Optional[typer.FileText], typer.Option(..., "--config", "-c", help="Path to a config file")]=None
):
# Read CSV data
data = read_and_normalize_csv_or_xlsx(input_file)
data = personalize_data_for_team(data, "Hounds")
# data = parse_datetime(data)
generate_calendar(data, config_file)
pass
@app.command(name="calendar-config")
def generate_calendar_configs(
input_file: Annotated[List[Path], typer.Argument(..., help="Path(s) to the CSV file")],
output_file: Annotated[Path, typer.Argument(..., help="Path(s) to the output config file")]
):
data = read_and_normalize_csv_or_xlsx(input_file)
teams = {row.get('visitor') for row in data}
teams.update({row.get('home') for row in data})
fields = {row.get('field') for row in data}
config = defaultdict(dict)
config['fields']['default'] = {
'bg_color': (0, 0, 0, 256)
}
config['teams']['default'] = {
'logo': ''
}
for field in fields:
config['fields'][field] = config['fields']['default']
for team in teams:
config['teams'][team] = config['teams']['default']
if output_file.is_dir:
output_file = output_file.joinpath('calendar_config.toml')
with output_file.open('w') as f:
toml.dump(config, f)
pass