aboutsummaryrefslogtreecommitdiff
path: root/nba/scores.py
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2025-04-05 13:50:08 -0500
committerGitHub <noreply@github.com>2025-04-05 13:50:08 -0500
commitfc0ea096722178bd609bce168d194c926d411a38 (patch)
tree1a587e9dcc7c2718731c20e4b667c7c9ca913369 /nba/scores.py
parent4d82554601ad5aba75accd4917bbad1969892203 (diff)
downloadnba-scores-fc0ea096722178bd609bce168d194c926d411a38.tar.gz
nba-scores-fc0ea096722178bd609bce168d194c926d411a38.tar.bz2
nba-scores-fc0ea096722178bd609bce168d194c926d411a38.zip
migrate from pylint to ruff (#3)
* migrate from pylint to ruff * Commit from GitHub Actions (Ruff) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'nba/scores.py')
-rw-r--r--nba/scores.py153
1 files changed, 79 insertions, 74 deletions
diff --git a/nba/scores.py b/nba/scores.py
index 6c4b660..47ed552 100644
--- a/nba/scores.py
+++ b/nba/scores.py
@@ -1,85 +1,90 @@
"""
Tabulates a scoreboard for today's games.
"""
+
from tabulate import tabulate
# ANSI escape codes for text formatting
-BOLD = '\033[1m'
-END = '\033[0m'
-RED = '\033[91m'
-GREEN = '\033[32m'
+BOLD = "\033[1m"
+END = "\033[0m"
+RED = "\033[91m"
+GREEN = "\033[32m"
+
# Function to get team record from standings
def get_team_record(team_name, standings) -> str:
- """
- Retrieves a team's win-loss record from the standings data.
-
- Args:
- team_name (str): Name of the team.
- standings (dict): Team standings data.
-
- Returns:
- record (str): Team's win-loss record in 'W-L' format. Defaults to 'N/A'.
- """
- for result_set in standings['resultSets']:
- if result_set['name'] == 'Standings':
- for team in result_set['rowSet']:
- if team[4] == team_name:
- return f"{team[12]}-{team[13]}"
- return "N/A"
+ """
+ Retrieves a team's win-loss record from the standings data.
+
+ Args:
+ team_name (str): Name of the team.
+ standings (dict): Team standings data.
+
+ Returns:
+ record (str): Team's win-loss record in 'W-L' format. Defaults to 'N/A'.
+ """
+ for result_set in standings["resultSets"]:
+ if result_set["name"] == "Standings":
+ for team in result_set["rowSet"]:
+ if team[4] == team_name:
+ return f"{team[12]}-{team[13]}"
+ return "N/A"
+
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.
- """
- scoreboard_data = games['scoreboard']
- games = scoreboard_data['games']
-
- # Prepare the table data
- table_data = []
- for game in games:
- home_team = game['homeTeam']['teamName']
- away_team = game['awayTeam']['teamName']
- game_status = game['gameStatusText']
- home_score = game['homeTeam']['score']
- away_score = game['awayTeam']['score']
-
- home_record = get_team_record(home_team, standings)
- away_record = get_team_record(away_team, standings)
-
- # Determine the winning team
- if home_score > away_score:
- home_team_bold = f"{BOLD}{GREEN}{home_team} ({home_record}){END}{END}"
- away_team_bold = f"{away_team} ({away_record}){END}"
- home_score_bold = f"{BOLD}{GREEN}{home_score}{END}{END}"
- away_score_bold = f"{away_score}{END}"
- elif away_score > home_score:
- home_team_bold = f"{home_team} ({home_record}){END}"
- away_team_bold = f"{BOLD}{GREEN}{away_team} ({away_record}){END}{END}"
- home_score_bold = f"{home_score}{END}"
- away_score_bold = f"{BOLD}{GREEN}{away_score}{END}{END}"
- else:
- home_team_bold = f"{home_team} ({home_record})"
- away_team_bold = f"{away_team} ({away_record})"
- home_score_bold = f"{home_score}"
- away_score_bold = f"{away_score}"
-
- # Determine games still in progress
- if game_status != "Final":
- game_status = f"{RED}{game_status}{END}"
-
- table_data.append([
- f"{home_team_bold}\n{away_team_bold}",
- f"{home_score_bold}\n{away_score_bold}",
- f"{BOLD}{game_status}{END}"
- ])
-
- # Define the table headers
- headers = ["Team", "Score", "Game Status"]
-
- # Print the table
- print(tabulate(table_data, headers=headers, tablefmt="grid"))
+ """
+ Prints the current day's games in a table format.
+
+ Args:
+ games (dict): JSON parsed games data.
+ standings (dict): Team standings data.
+ """
+ scoreboard_data = games["scoreboard"]
+ games = scoreboard_data["games"]
+
+ # Prepare the table data
+ table_data = []
+ for game in games:
+ home_team = game["homeTeam"]["teamName"]
+ away_team = game["awayTeam"]["teamName"]
+ game_status = game["gameStatusText"]
+ home_score = game["homeTeam"]["score"]
+ away_score = game["awayTeam"]["score"]
+
+ home_record = get_team_record(home_team, standings)
+ away_record = get_team_record(away_team, standings)
+
+ # Determine the winning team
+ if home_score > away_score:
+ home_team_bold = f"{BOLD}{GREEN}{home_team} ({home_record}){END}{END}"
+ away_team_bold = f"{away_team} ({away_record}){END}"
+ home_score_bold = f"{BOLD}{GREEN}{home_score}{END}{END}"
+ away_score_bold = f"{away_score}{END}"
+ elif away_score > home_score:
+ home_team_bold = f"{home_team} ({home_record}){END}"
+ away_team_bold = f"{BOLD}{GREEN}{away_team} ({away_record}){END}{END}"
+ home_score_bold = f"{home_score}{END}"
+ away_score_bold = f"{BOLD}{GREEN}{away_score}{END}{END}"
+ else:
+ home_team_bold = f"{home_team} ({home_record})"
+ away_team_bold = f"{away_team} ({away_record})"
+ home_score_bold = f"{home_score}"
+ away_score_bold = f"{away_score}"
+
+ # Determine games still in progress
+ if game_status != "Final":
+ game_status = f"{RED}{game_status}{END}"
+
+ table_data.append(
+ [
+ f"{home_team_bold}\n{away_team_bold}",
+ f"{home_score_bold}\n{away_score_bold}",
+ f"{BOLD}{game_status}{END}",
+ ]
+ )
+
+ # Define the table headers
+ headers = ["Team", "Score", "Game Status"]
+
+ # Print the table
+ print(tabulate(table_data, headers=headers, tablefmt="grid"))