Commit c112ed86ba
Verified · cmc
Layout: unified · split
build/lib/nba/__pycache__/bracket.cpython-314.pyc added
Binary file not shown.
build/lib/nba/bracket.py +32 −4
| @@ -3,6 +3,7 @@ Fetches and formats the NBA playoff bracket. | ||
| 3 | 3 | """ |
| 4 | 4 | |
| 5 | 5 | import json |
| 6 | import re | |
| 6 | 7 | from collections import defaultdict |
| 7 | 8 | from typing import Optional |
| 8 | 9 | |
| @@ -13,6 +14,10 @@ from nba_api.stats.static import teams | ||
| 13 | 14 | BOLD = "\033[1m" |
| 14 | 15 | END = "\033[0m" |
| 15 | 16 | GREEN = "\033[32m" |
| 17 | RED = "\033[91m" | |
| 18 | YELLOW = "\033[33m" | |
| 19 | CYAN = "\033[36m" | |
| 20 | ANSI_RE = re.compile(r"\033\[[0-9;]*m") | |
| 16 | 21 | |
| 17 | 22 | ROUND_LABELS = { |
| 18 | 23 | 1: "First Round", |
| @@ -54,6 +59,8 @@ def get_bracket_table(data: dict) -> str: | ||
| 54 | 59 | return "\n".join( |
| 55 | 60 | [ |
| 56 | 61 | _center(f"{BOLD}NBA Playoff Bracket{END}", 74), |
| 62 | f"{GREEN}* Advanced{END} {RED}x Eliminated{END} " | |
| 63 | f"{CYAN}> Series lead{END} {YELLOW}! Can clinch next win{END}", | |
| 57 | 64 | "", |
| 58 | 65 | _render_conference("Western", summaries), |
| 59 | 66 | "", |
| @@ -182,7 +189,7 @@ def _render_finals(summaries: dict) -> str: | ||
| 182 | 189 | if final is None: |
| 183 | 190 | lines.append("Winner TBD") |
| 184 | 191 | elif final["winner"]: |
| 185 | lines.append(f"{GREEN}{final['winner']} wins the Finals{END}") | |
| 192 | lines.append(f"{BOLD}{GREEN}{final['winner']} wins the Finals{END}") | |
| 186 | 193 | return "\n".join(lines) |
| 187 | 194 | |
| 188 | 195 | |
| @@ -209,20 +216,36 @@ def _series_box(summary: Optional[dict], width: int) -> str: | ||
| 209 | 216 | visitor = _team_line( |
| 210 | 217 | summary["visitor_abbr"], |
| 211 | 218 | summary["visitor_wins"], |
| 219 | summary["home_wins"], | |
| 212 | 220 | summary["winner"] == summary["visitor_abbr"], |
| 221 | summary["winner"] == summary["home_abbr"], | |
| 213 | 222 | ) |
| 214 | 223 | home = _team_line( |
| 215 | 224 | summary["home_abbr"], |
| 216 | 225 | summary["home_wins"], |
| 226 | summary["visitor_wins"], | |
| 217 | 227 | summary["winner"] == summary["home_abbr"], |
| 228 | summary["winner"] == summary["visitor_abbr"], | |
| 218 | 229 | ) |
| 219 | return f"{visitor} / {home}".ljust(width) | |
| 230 | return _pad_ansi(f"{visitor} / {home}", width) | |
| 220 | 231 | |
| 221 | 232 | |
| 222 | def _team_line(abbr: str, wins: int, won_series: bool) -> str: | |
| 233 | def _team_line( | |
| 234 | abbr: str, | |
| 235 | wins: int, | |
| 236 | opponent_wins: int, | |
| 237 | won_series: bool, | |
| 238 | lost_series: bool, | |
| 239 | ) -> str: | |
| 223 | 240 | label = f"{abbr} {wins}" |
| 224 | 241 | if won_series: |
| 225 | return f"{label}*" | |
| 242 | return f"{BOLD}{GREEN}{label}*{END}" | |
| 243 | if lost_series: | |
| 244 | return f"{RED}{label}x{END}" | |
| 245 | if wins == 3: | |
| 246 | return f"{BOLD}{YELLOW}{label}!{END}" | |
| 247 | if wins > opponent_wins: | |
| 248 | return f"{CYAN}{label}>{END}" | |
| 226 | 249 | return label |
| 227 | 250 | |
| 228 | 251 | |
| @@ -248,6 +271,11 @@ def _center(text: str, width: int) -> str: | ||
| 248 | 271 | return text.center(width) |
| 249 | 272 | |
| 250 | 273 | |
| 274 | def _pad_ansi(text: str, width: int) -> str: | |
| 275 | visible_length = len(ANSI_RE.sub("", text)) | |
| 276 | return text + " " * max(width - visible_length, 0) | |
| 277 | ||
| 278 | ||
| 251 | 279 | def _round_number(series_id: str) -> int: |
| 252 | 280 | try: |
| 253 | 281 | return int(series_id[-3:-1]) |
nba/bracket.py +32 −4
| @@ -3,6 +3,7 @@ Fetches and formats the NBA playoff bracket. | ||
| 3 | 3 | """ |
| 4 | 4 | |
| 5 | 5 | import json |
| 6 | import re | |
| 6 | 7 | from collections import defaultdict |
| 7 | 8 | from typing import Optional |
| 8 | 9 | |
| @@ -13,6 +14,10 @@ from nba_api.stats.static import teams | ||
| 13 | 14 | BOLD = "\033[1m" |
| 14 | 15 | END = "\033[0m" |
| 15 | 16 | GREEN = "\033[32m" |
| 17 | RED = "\033[91m" | |
| 18 | YELLOW = "\033[33m" | |
| 19 | CYAN = "\033[36m" | |
| 20 | ANSI_RE = re.compile(r"\033\[[0-9;]*m") | |
| 16 | 21 | |
| 17 | 22 | ROUND_LABELS = { |
| 18 | 23 | 1: "First Round", |
| @@ -54,6 +59,8 @@ def get_bracket_table(data: dict) -> str: | ||
| 54 | 59 | return "\n".join( |
| 55 | 60 | [ |
| 56 | 61 | _center(f"{BOLD}NBA Playoff Bracket{END}", 74), |
| 62 | f"{GREEN}* Advanced{END} {RED}x Eliminated{END} " | |
| 63 | f"{CYAN}> Series lead{END} {YELLOW}! Can clinch next win{END}", | |
| 57 | 64 | "", |
| 58 | 65 | _render_conference("Western", summaries), |
| 59 | 66 | "", |
| @@ -182,7 +189,7 @@ def _render_finals(summaries: dict) -> str: | ||
| 182 | 189 | if final is None: |
| 183 | 190 | lines.append("Winner TBD") |
| 184 | 191 | elif final["winner"]: |
| 185 | lines.append(f"{GREEN}{final['winner']} wins the Finals{END}") | |
| 192 | lines.append(f"{BOLD}{GREEN}{final['winner']} wins the Finals{END}") | |
| 186 | 193 | return "\n".join(lines) |
| 187 | 194 | |
| 188 | 195 | |
| @@ -209,20 +216,36 @@ def _series_box(summary: Optional[dict], width: int) -> str: | ||
| 209 | 216 | visitor = _team_line( |
| 210 | 217 | summary["visitor_abbr"], |
| 211 | 218 | summary["visitor_wins"], |
| 219 | summary["home_wins"], | |
| 212 | 220 | summary["winner"] == summary["visitor_abbr"], |
| 221 | summary["winner"] == summary["home_abbr"], | |
| 213 | 222 | ) |
| 214 | 223 | home = _team_line( |
| 215 | 224 | summary["home_abbr"], |
| 216 | 225 | summary["home_wins"], |
| 226 | summary["visitor_wins"], | |
| 217 | 227 | summary["winner"] == summary["home_abbr"], |
| 228 | summary["winner"] == summary["visitor_abbr"], | |
| 218 | 229 | ) |
| 219 | return f"{visitor} / {home}".ljust(width) | |
| 230 | return _pad_ansi(f"{visitor} / {home}", width) | |
| 220 | 231 | |
| 221 | 232 | |
| 222 | def _team_line(abbr: str, wins: int, won_series: bool) -> str: | |
| 233 | def _team_line( | |
| 234 | abbr: str, | |
| 235 | wins: int, | |
| 236 | opponent_wins: int, | |
| 237 | won_series: bool, | |
| 238 | lost_series: bool, | |
| 239 | ) -> str: | |
| 223 | 240 | label = f"{abbr} {wins}" |
| 224 | 241 | if won_series: |
| 225 | return f"{label}*" | |
| 242 | return f"{BOLD}{GREEN}{label}*{END}" | |
| 243 | if lost_series: | |
| 244 | return f"{RED}{label}x{END}" | |
| 245 | if wins == 3: | |
| 246 | return f"{BOLD}{YELLOW}{label}!{END}" | |
| 247 | if wins > opponent_wins: | |
| 248 | return f"{CYAN}{label}>{END}" | |
| 226 | 249 | return label |
| 227 | 250 | |
| 228 | 251 | |
| @@ -248,6 +271,11 @@ def _center(text: str, width: int) -> str: | ||
| 248 | 271 | return text.center(width) |
| 249 | 272 | |
| 250 | 273 | |
| 274 | def _pad_ansi(text: str, width: int) -> str: | |
| 275 | visible_length = len(ANSI_RE.sub("", text)) | |
| 276 | return text + " " * max(width - visible_length, 0) | |
| 277 | ||
| 278 | ||
| 251 | 279 | def _round_number(series_id: str) -> int: |
| 252 | 280 | try: |
| 253 | 281 | return int(series_id[-3:-1]) |
nba_scores.egg-info/PKG-INFO +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | Metadata-Version: 2.4 |
| 2 | 2 | Name: nba-scores |
| 3 | Version: 0.2.2 | |
| 3 | Version: 0.2.3 | |
| 4 | 4 | Summary: A CLI interface to get current NBA scores and standings. |
| 5 | 5 | Author-email: Christian Cleberg <hello@cleberg.net> |
| 6 | 6 | License-Expression: GPL-3.0-or-later |
pyproject.toml +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [project] |
| 2 | 2 | name = "nba-scores" |
| 3 | version = "0.2.2" | |
| 3 | version = "0.2.3" | |
| 4 | 4 | authors = [ |
| 5 | 5 | { name="Christian Cleberg", email="hello@cleberg.net" }, |
| 6 | 6 | ] |