diff options
Diffstat (limited to 'build')
| -rw-r--r-- | build/lib/nba/box_score.py | 55 | ||||
| -rw-r--r-- | build/lib/nba/cli.py | 8 | ||||
| -rw-r--r-- | build/lib/nba/leaders.py | 26 | ||||
| -rw-r--r-- | build/lib/nba/playoff.py | 39 | ||||
| -rw-r--r-- | build/lib/nba/standings.py | 15 | ||||
| -rw-r--r-- | build/lib/nba/tui/app.py | 20 |
6 files changed, 100 insertions, 63 deletions
diff --git a/build/lib/nba/box_score.py b/build/lib/nba/box_score.py index 8c2ef01..f641397 100644 --- a/build/lib/nba/box_score.py +++ b/build/lib/nba/box_score.py @@ -10,7 +10,21 @@ from nba_api.live.nba.endpoints.boxscore import BoxScore BOLD = "\033[1m" END = "\033[0m" -_HEADERS = ["Player", "Pos", "Min", "Pts", "Reb", "Ast", "Stl", "Blk", "TO", "FG", "3P", "FT", "+/-"] +_HEADERS = [ + "Player", + "Pos", + "Min", + "Pts", + "Reb", + "Ast", + "Stl", + "Blk", + "TO", + "FG", + "3P", + "FT", + "+/-", +] def fetch_box_score(game_id: str) -> dict: @@ -36,21 +50,23 @@ def _player_rows(players: list) -> list: if p.get("status") == "INACTIVE": continue s = p.get("statistics", {}) - rows.append([ - p.get("name", ""), - p.get("position", ""), - _parse_minutes(s.get("minutes", "")), - s.get("points", 0), - s.get("reboundsTotal", 0), - s.get("assists", 0), - s.get("steals", 0), - s.get("blocks", 0), - s.get("turnovers", 0), - f"{s.get('fieldGoalsMade', 0)}/{s.get('fieldGoalsAttempted', 0)}", - f"{s.get('threePointersMade', 0)}/{s.get('threePointersAttempted', 0)}", - f"{s.get('freeThrowsMade', 0)}/{s.get('freeThrowsAttempted', 0)}", - s.get("plusMinusPoints", 0), - ]) + rows.append( + [ + p.get("name", ""), + p.get("position", ""), + _parse_minutes(s.get("minutes", "")), + s.get("points", 0), + s.get("reboundsTotal", 0), + s.get("assists", 0), + s.get("steals", 0), + s.get("blocks", 0), + s.get("turnovers", 0), + f"{s.get('fieldGoalsMade', 0)}/{s.get('fieldGoalsAttempted', 0)}", + f"{s.get('threePointersMade', 0)}/{s.get('threePointersAttempted', 0)}", + f"{s.get('freeThrowsMade', 0)}/{s.get('freeThrowsAttempted', 0)}", + s.get("plusMinusPoints", 0), + ] + ) return rows @@ -60,13 +76,6 @@ def get_box_score_tables(data: dict) -> tuple: home = game["homeTeam"] away = game["awayTeam"] - home_title = ( - f"{BOLD}{home['teamCity']} {home['teamName']} " - f"{home['score']} — {away['score']} " - f"{away['teamCity']} {away['teamName']}{END} " - f" [{game.get('gameStatusText', '')}]" - ) - home_rows = _player_rows(home.get("players", [])) away_rows = _player_rows(away.get("players", [])) diff --git a/build/lib/nba/cli.py b/build/lib/nba/cli.py index e5f460d..2e04b8b 100644 --- a/build/lib/nba/cli.py +++ b/build/lib/nba/cli.py @@ -19,9 +19,7 @@ def nba() -> None: parser.add_argument( "--standings", "-st", action="store_true", help="Display the standings" ) - parser.add_argument( - "--tui", action="store_true", help="Launch the interactive TUI" - ) + parser.add_argument("--tui", action="store_true", help="Launch the interactive TUI") parser.add_argument( "--refresh", type=int, @@ -47,4 +45,6 @@ def nba() -> None: elif args.standings: standings.build_standings(ranks) else: - print("Please specify --scores or --standings (or use --tui for interactive mode)") + print( + "Please specify --scores or --standings (or use --tui for interactive mode)" + ) diff --git a/build/lib/nba/leaders.py b/build/lib/nba/leaders.py index aa6f3b4..27e7901 100644 --- a/build/lib/nba/leaders.py +++ b/build/lib/nba/leaders.py @@ -25,20 +25,23 @@ CATEGORIES = [ # Extra columns to show alongside RANK, PLAYER, TEAM, GP for each category _EXTRA_COLS = { - "PTS": ["PTS", "FGM", "FGA", "FG_PCT", "FTM", "FTA", "FT_PCT"], - "REB": ["REB", "OREB", "DREB", "GP"], - "AST": ["AST", "TOV", "AST_TOV", "GP"], - "STL": ["STL", "TOV", "GP"], - "BLK": ["BLK", "PF", "GP"], - "EFF": ["EFF", "PTS", "REB", "AST", "GP"], + "PTS": ["PTS", "FGM", "FGA", "FG_PCT", "FTM", "FTA", "FT_PCT"], + "REB": ["REB", "OREB", "DREB", "GP"], + "AST": ["AST", "TOV", "AST_TOV", "GP"], + "STL": ["STL", "TOV", "GP"], + "BLK": ["BLK", "PF", "GP"], + "EFF": ["EFF", "PTS", "REB", "AST", "GP"], "FG_PCT": ["FG_PCT", "FGM", "FGA", "PTS"], "FT_PCT": ["FT_PCT", "FTM", "FTA", "PTS"], - "FG3_PCT":["FG3_PCT", "FG3M", "FG3A", "PTS"], + "FG3_PCT": ["FG3_PCT", "FG3M", "FG3A", "PTS"], } _DISPLAY_NAMES = { - "FG_PCT": "FG%", "FT_PCT": "FT%", "FG3_PCT": "3P%", - "FG3M": "3PM", "FG3A": "3PA", + "FG_PCT": "FG%", + "FT_PCT": "FT%", + "FG3_PCT": "3P%", + "FG3M": "3PM", + "FG3A": "3PA", "AST_TOV": "AST/TO", } @@ -61,10 +64,7 @@ def get_leaders_table(data: dict, category: str = "PTS") -> str: wanted = base + extra idx = {h: i for i, h in enumerate(headers)} - table_data = [ - [row[idx[col]] for col in wanted if col in idx] - for row in rows[:25] - ] + table_data = [[row[idx[col]] for col in wanted if col in idx] for row in rows[:25]] display_headers = [_DISPLAY_NAMES.get(c, c) for c in wanted if c in idx] cat_label = dict(CATEGORIES).get(category, category) diff --git a/build/lib/nba/playoff.py b/build/lib/nba/playoff.py index eb3b12b..42c3b0b 100644 --- a/build/lib/nba/playoff.py +++ b/build/lib/nba/playoff.py @@ -21,6 +21,7 @@ def fetch_playoff_picture() -> dict: def _clinch_status(row: list, idx: dict) -> str: """Return a color-coded status string from clinch/elimination columns.""" + def val(col): return row[idx[col]] if col in idx else None @@ -54,19 +55,31 @@ def _build_conference_table(result_sets: list, name: str) -> str: losses = get(row, "LOSSES") pct = get(row, "PCT") pct_str = f"{float(pct):.3f}" if pct not in ("", None) else "" - table_data.append([ - get(row, "RANK"), - get(row, "TEAM"), - f"{wins}-{losses}", - pct_str, - get(row, "GB"), - get(row, "HOME"), - get(row, "AWAY"), - get(row, "CONF"), - _clinch_status(row, idx), - ]) - - display_headers = ["#", "Team", "W-L", "PCT", "GB", "HOME", "AWAY", "CONF", "Status"] + table_data.append( + [ + get(row, "RANK"), + get(row, "TEAM"), + f"{wins}-{losses}", + pct_str, + get(row, "GB"), + get(row, "HOME"), + get(row, "AWAY"), + get(row, "CONF"), + _clinch_status(row, idx), + ] + ) + + display_headers = [ + "#", + "Team", + "W-L", + "PCT", + "GB", + "HOME", + "AWAY", + "CONF", + "Status", + ] conf_label = "Eastern" if "East" in name else "Western" title = f"{BOLD}{conf_label} Conference Playoff Picture:{END}" return title + "\n" + tabulate(table_data, headers=display_headers, tablefmt="grid") diff --git a/build/lib/nba/standings.py b/build/lib/nba/standings.py index 3abb1c0..e71dc2b 100644 --- a/build/lib/nba/standings.py +++ b/build/lib/nba/standings.py @@ -27,7 +27,9 @@ def _build_conference_table(standings, conference: str) -> str: streak = team[35] strk_color = ( - f"{RED}{streak}{END}" if int(streak) < 0 else f"{GREEN}{streak}{END}" + f"{RED}{streak}{END}" + if int(streak) < 0 + else f"{GREEN}{streak}{END}" ) data.append( @@ -47,9 +49,8 @@ def _build_conference_table(standings, conference: str) -> str: headers = ["Rank", "Team", "W-L", "PCT", "GB", "STRK", "L10", "HOME", "AWAY"] label = "Eastern" if conference == "East" else "Western" - return ( - f"{BOLD}{label} Conference Standings:{END}\n" - + tabulate(data, headers=headers, tablefmt="grid") + return f"{BOLD}{label} Conference Standings:{END}\n" + tabulate( + data, headers=headers, tablefmt="grid" ) @@ -73,7 +74,11 @@ def get_standings_tables(standings) -> str: Returns: str: Formatted standings string with ANSI color codes for both conferences. """ - return get_east_standings_table(standings) + "\n\n" + get_west_standings_table(standings) + return ( + get_east_standings_table(standings) + + "\n\n" + + get_west_standings_table(standings) + ) def build_standings(standings) -> None: diff --git a/build/lib/nba/tui/app.py b/build/lib/nba/tui/app.py index cfa72a6..4ade311 100644 --- a/build/lib/nba/tui/app.py +++ b/build/lib/nba/tui/app.py @@ -182,11 +182,15 @@ class NBAApp(App): self.query_one(TabbedContent).active = "boxscore" async def action_prev_category(self) -> None: - self._leaders_cat_idx = (self._leaders_cat_idx - 1) % len(leaders_mod.CATEGORIES) + self._leaders_cat_idx = (self._leaders_cat_idx - 1) % len( + leaders_mod.CATEGORIES + ) await self._refresh_leaders() async def action_next_category(self) -> None: - self._leaders_cat_idx = (self._leaders_cat_idx + 1) % len(leaders_mod.CATEGORIES) + self._leaders_cat_idx = (self._leaders_cat_idx + 1) % len( + leaders_mod.CATEGORIES + ) await self._refresh_leaders() # ------------------------------------------------------------------ # @@ -198,13 +202,17 @@ class NBAApp(App): self.query_one("#leaders-content", Static).update(f"Loading {label} leaders...") loop = asyncio.get_event_loop() try: - data = await loop.run_in_executor(None, lambda: leaders_mod.fetch_leaders(cat)) + data = await loop.run_in_executor( + None, lambda: leaders_mod.fetch_leaders(cat) + ) self._leaders_data = data self.query_one("#leaders-content", Static).update( Text.from_ansi(leaders_mod.get_leaders_table(data, cat)) ) except Exception as exc: - self.query_one("#leaders-content", Static).update(f"Error loading leaders: {exc}") + self.query_one("#leaders-content", Static).update( + f"Error loading leaders: {exc}" + ) async def _load_box_score(self, game_idx: int) -> None: if not self._games: @@ -233,5 +241,7 @@ class NBAApp(App): self.query_one("#home-content", Static).update(Text.from_ansi(home_table)) self.query_one("#away-content", Static).update(Text.from_ansi(away_table)) except Exception as exc: - self.query_one("#home-content", Static).update(f"Error loading box score: {exc}") + self.query_one("#home-content", Static).update( + f"Error loading box score: {exc}" + ) self.query_one("#away-content", Static).update("") |
