2025
This commit is contained in:
54
src/apps/generate/calendar.py
Normal file
54
src/apps/generate/calendar.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from typing import Annotated, List
|
||||
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, 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[typer.FileText], typer.Argument(..., help="Path(s) to the CSV file")],
|
||||
):
|
||||
# Read CSV data
|
||||
data = read_and_normalize_csv(input_file)
|
||||
data = personalize_data_for_team(data, "Hounds")
|
||||
# data = parse_datetime(data)
|
||||
|
||||
generate_calendar(data)
|
||||
pass
|
||||
|
||||
@app.command(name="calendar-config")
|
||||
def generate_calendar_configs(
|
||||
input_file: Annotated[List[typer.FileText], 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(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
|
||||
Reference in New Issue
Block a user