From 4cbe592e0a0fae13f0a89918a66fd983dd84464f Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Wed, 15 Apr 2026 22:28:45 -0500 Subject: feat: add Textual TUI with auto-refresh, leaders, playoff picture, and box score MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces an interactive terminal UI via the `--tui` flag backed by the Textual framework. Scores and standings auto-refresh on a configurable interval (default 60s, minimum 10s) using asyncio with nba_api calls offloaded to a thread pool to keep the event loop unblocked. New tabs: - Scores / Standings (existing views, now live-updating) - Leaders: top-25 by stat category, cycle with < / > keys - Playoff Picture: conference seeding with clinch/elimination status - Box Score: per-player live stats, load any game with keys 1–9 Refactored scores.py and standings.py to separate rendering from I/O (get_scoreboard_table, get_east/west_standings_table), keeping the existing static CLI path fully intact. Added -sc / -st shortcut flags. Adds textual>=0.89.1,<7.0 dependency, build-system declaration for uv, and package-data entry for the bundled .tcss stylesheet. --- nba/scores.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'nba/scores.py') diff --git a/nba/scores.py b/nba/scores.py index 47ed552..28e4e82 100644 --- a/nba/scores.py +++ b/nba/scores.py @@ -31,20 +31,26 @@ def get_team_record(team_name, standings) -> str: return "N/A" -def build_scoreboard(games, standings) -> None: +def get_scoreboard_table(games, standings) -> str: """ - Prints the current day's games in a table format. + Builds and returns the current day's games as a formatted table string. Args: games (dict): JSON parsed games data. standings (dict): Team standings data. + + Returns: + str: Formatted table string with ANSI color codes. """ scoreboard_data = games["scoreboard"] - games = scoreboard_data["games"] + game_list = scoreboard_data["games"] + + if not game_list: + return "No games scheduled today." # Prepare the table data table_data = [] - for game in games: + for game in game_list: home_team = game["homeTeam"]["teamName"] away_team = game["awayTeam"]["teamName"] game_status = game["gameStatusText"] @@ -86,5 +92,15 @@ def build_scoreboard(games, standings) -> None: # Define the table headers headers = ["Team", "Score", "Game Status"] - # Print the table - print(tabulate(table_data, headers=headers, tablefmt="grid")) + return tabulate(table_data, headers=headers, tablefmt="grid") + + +def build_scoreboard(games, standings) -> None: + """ + Prints the current day's games in a table format. + + Args: + games (dict): JSON parsed games data. + standings (dict): Team standings data. + """ + print(get_scoreboard_table(games, standings)) -- cgit v1.2.3