krz/nba-scores

A CLI/TUI app for NBA scores.

clone: git clone https://gitbay.org/krz/nba-scores.git

fc0ea096722178bd609bce168d194c926d411a38

signed_unknown_key

author: Christian Cleberg <hello@cleberg.net> · 2025-04-05T18:50:08Z
committer: <noreply@github.com>

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>
 .github/workflows/pylint.yml |  22 +++++--
 nba/__main__.py              |   1 +
 nba/cli.py                   |  32 +++++----
 nba/fetch_data.py            |  34 +++++-----
 nba/scores.py                | 153 ++++++++++++++++++++++---------------------
 nba/standings.py             | 130 ++++++++++++++++++------------------
 6 files changed, 200 insertions(+), 172 deletions(-)

diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml
index 2a34a73..80f35df 100644
--- a/.github/workflows/pylint.yml
+++ b/.github/workflows/pylint.yml
@@ -1,4 +1,4 @@
-name: Pylint
+name: Ruff
 
 on: [push]
 
@@ -7,18 +7,28 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        python-version: ["3.8", "3.9", "3.10"]
+        python-version: ["3.x"]
     steps:
     - uses: actions/checkout@v4
     - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v4
+      uses: actions/setup-python@v5
       with:
         python-version: ${{ matrix.python-version }}
+        ref: ${{ github.event.pull_request.head.ref }}
     - name: Install dependencies
       run: |
         python -m pip install --upgrade pip
         pip install -r requirements.txt
-        pip install pylint
-    - name: Analysing the code with pylint
+    - name: Install Ruff
+      uses: astral-sh/ruff-action@v3.2.2
+    - name: Ruff Actions
       run: |
-        pylint -d R0801 -d W0311 -d R0914 $(git ls-files '*.py')
\ No newline at end of file
+        ruff check --fix
+        ruff format
+    - name: Add and Commit
+      uses: EndBug/add-and-commit@v9
+      env:
+        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        default_author: github_actions
+        pathspec_error_handling: ignore
diff --git a/nba/__main__.py b/nba/__main__.py
index 0605298..6619883 100644
--- a/nba/__main__.py
+++ b/nba/__main__.py
@@ -4,4 +4,5 @@ Entry point for the app.
 
 if __name__ == "__main__":
     from nba.cli import nba
+
     nba()
diff --git a/nba/cli.py b/nba/cli.py
index c41055f..82c3883 100644
--- a/nba/cli.py
+++ b/nba/cli.py
@@ -3,23 +3,27 @@ This script uses argparse to parse command line arguments.
 
 It imports the required modules and sets up a parser with basic options for demonstration purposes.
 """
+
 import argparse
 from nba import fetch_data, scores, standings
 
+
 def nba() -> None:
-        """
-        Parse command-line arguments and display either scoreboard or standings.
-        """
-        parser = argparse.ArgumentParser(description="NBA Scoreboard and Standings")
-        parser.add_argument('--scores', '-sc', action='store_true', help='Display the scoreboard')
-        parser.add_argument('--standings', '-st', action='store_true', help='Display the standings')
-        args = parser.parse_args()
+    """
+    Parse command-line arguments and display either scoreboard or standings.
+    """
+    parser = argparse.ArgumentParser(description="NBA Scoreboard and Standings")
+    parser.add_argument("--scores", action="store_true", help="Display the scoreboard")
+    parser.add_argument(
+        "--standings", action="store_true", help="Display the standings"
+    )
+    args = parser.parse_args()
 
-        games, ranks = fetch_data.fetch_data()
+    games, ranks = fetch_data.fetch_data()
 
-        if args.scores:
-                scores.build_scoreboard(games, ranks)
-        elif args.standings:
-                standings.build_standings(ranks)
-        else:
-                print("Please specify --scores or --standings")
+    if args.scores:
+        scores.build_scoreboard(games, ranks)
+    elif args.standings:
+        standings.build_standings(ranks)
+    else:
+        print("Please specify --scores or --standings")
diff --git a/nba/fetch_data.py b/nba/fetch_data.py
index 71cac33..49503cc 100644
--- a/nba/fetch_data.py
+++ b/nba/fetch_data.py
@@ -1,28 +1,30 @@
 """
 Fetches data for use in other modules.
 """
+
 import json
 from nba_api.live.nba.endpoints import scoreboard
 from nba_api.stats.endpoints import leaguestandings
 
+
 def fetch_data() -> tuple:
-	"""
-	Fetches live NBA scoreboard data and standings from the NBA API.
+    """
+    Fetches live NBA scoreboard data and standings from the NBA API.
 
-	Returns:
-		games (dict): JSON parsed games data.
-		standings (dict): JSON parsed team standings data.
-	"""
-	# Get today's scoreboard data
-	games_endpoint = scoreboard.ScoreBoard()
-	games_json = games_endpoint.get_json()
+    Returns:
+            games (dict): JSON parsed games data.
+            standings (dict): JSON parsed team standings data.
+    """
+    # Get today's scoreboard data
+    games_endpoint = scoreboard.ScoreBoard()
+    games_json = games_endpoint.get_json()
 
-	# Get league standings
-	standings_endpoint = leaguestandings.LeagueStandings()
-	standings_json = standings_endpoint.get_json()
+    # Get league standings
+    standings_endpoint = leaguestandings.LeagueStandings()
+    standings_json = standings_endpoint.get_json()
 
-	# Parse the JSON strings into Python dictionaries
-	games = json.loads(games_json)
-	standings = json.loads(standings_json)
+    # Parse the JSON strings into Python dictionaries
+    games = json.loads(games_json)
+    standings = json.loads(standings_json)
 
-	return games, standings
+    return games, standings
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"))
diff --git a/nba/standings.py b/nba/standings.py
index 3c796ee..9b6a56e 100644
--- a/nba/standings.py
+++ b/nba/standings.py
@@ -1,77 +1,83 @@
 """
 Tabulate the current conference standings.
 """
+
 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"
+
 
 def build_standings(standings) -> None:
-	"""
-	Prints team standings in two separate tables.
+    """
+    Prints team standings in two separate tables.
 
-	Args:
-		standings (dict): Team standings data.
-	"""
-	eastern_data = []
-	western_data = []
-	eastern_rank = 1
-	western_rank = 1
+    Args:
+            standings (dict): Team standings data.
+    """
+    eastern_data = []
+    western_data = []
+    eastern_rank = 1
+    western_rank = 1
 
-	for result_set in standings['resultSets']:
-		if result_set['name'] == 'Standings':
-			for team in result_set['rowSet']:
-				conference = team[5]
-				team_name = team[4]
-				wins = team[12]
-				losses = team[13]
-				win_pct = team[14]
-				gb = team[37]
-				home_record = team[17]
-				away_record = team[18]
-				last_10 = team[19]
-				streak = team[35]
+    for result_set in standings["resultSets"]:
+        if result_set["name"] == "Standings":
+            for team in result_set["rowSet"]:
+                conference = team[5]
+                team_name = team[4]
+                wins = team[12]
+                losses = team[13]
+                win_pct = team[14]
+                gb = team[37]
+                home_record = team[17]
+                away_record = team[18]
+                last_10 = team[19]
+                streak = team[35]
 
-				if int(streak) < 0:
-					strk_color = f"{RED}{streak}{END}"
-				else:
-					strk_color = f"{GREEN}{streak}{END}"
+                if int(streak) < 0:
+                    strk_color = f"{RED}{streak}{END}"
+                else:
+                    strk_color = f"{GREEN}{streak}{END}"
 
-				if conference == "East":
-					eastern_data.append([
-					f"{eastern_rank}",
-					f"{team_name}",
-					f"{wins}-{losses}",
-					f"{win_pct:.3f}",
-					f"{gb}",
-					f"{strk_color}",
-					f"{last_10}",
-					f"{home_record}",
-					f"{away_record}"
-					])
-					eastern_rank += 1
-				elif conference == "West":
-					western_data.append([
-						f"{western_rank}",
-						f"{team_name}",
-						f"{wins}-{losses}",
-						f"{win_pct:.3f}",
-						f"{gb}",
-						f"{strk_color}",
-						f"{last_10}",
-						f"{home_record}",
-						f"{away_record}"
-					])
-					western_rank += 1
+                if conference == "East":
+                    eastern_data.append(
+                        [
+                            f"{eastern_rank}",
+                            f"{team_name}",
+                            f"{wins}-{losses}",
+                            f"{win_pct:.3f}",
+                            f"{gb}",
+                            f"{strk_color}",
+                            f"{last_10}",
+                            f"{home_record}",
+                            f"{away_record}",
+                        ]
+                    )
+                    eastern_rank += 1
+                elif conference == "West":
+                    western_data.append(
+                        [
+                            f"{western_rank}",
+                            f"{team_name}",
+                            f"{wins}-{losses}",
+                            f"{win_pct:.3f}",
+                            f"{gb}",
+                            f"{strk_color}",
+                            f"{last_10}",
+                            f"{home_record}",
+                            f"{away_record}",
+                        ]
+                    )
+                    western_rank += 1
 
-	headers = ["Rank", "Team", "W-L", "PCT", "GB", "STRK", "L10", "HOME", "AWAY"]
+    headers = ["Rank", "Team", "W-L", "PCT", "GB", "STRK", "L10", "HOME", "AWAY"]
 
-	print(f"{BOLD}Eastern Conference Standings:{END}")
-	print(tabulate(eastern_data, headers=headers, tablefmt="grid"))
+    print(f"{BOLD}Eastern Conference Standings:{END}")
+    print(tabulate(eastern_data, headers=headers, tablefmt="grid"))
 
-	print("\n")
-	print(f"{BOLD}Western Conference Standings:{END}")
-	print(tabulate(western_data, headers=headers, tablefmt="grid"))
+    print("\n")
+    print(f"{BOLD}Western Conference Standings:{END}")
+    print(tabulate(western_data, headers=headers, tablefmt="grid"))