Commit fc0ea09672

fc0ea096722178bd609bce168d194c926d411a38

parent: 4d82554601

Unregistered key

cmc <hello@cleberg.net> · 2025-04-05 18:50 UTC
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>

Layout: unified · split

.github/workflows/pylint.yml +16 −6
@@ -1,4 +1,4 @@
1name: Pylint 1name: Ruff
2 2
3on: [push] 3on: [push]
4 4
@@ -7,18 +7,28 @@ jobs:
7 runs-on: ubuntu-latest 7 runs-on: ubuntu-latest
8 strategy: 8 strategy:
9 matrix: 9 matrix:
10 python-version: ["3.8", "3.9", "3.10"] 10 python-version: ["3.x"]
11 steps: 11 steps:
12 - uses: actions/checkout@v4 12 - uses: actions/checkout@v4
13 - name: Set up Python ${{ matrix.python-version }} 13 - name: Set up Python ${{ matrix.python-version }}
14 uses: actions/setup-python@v4 14 uses: actions/setup-python@v5
15 with: 15 with:
16 python-version: ${{ matrix.python-version }} 16 python-version: ${{ matrix.python-version }}
17 ref: ${{ github.event.pull_request.head.ref }}
17 - name: Install dependencies 18 - name: Install dependencies
18 run: | 19 run: |
19 python -m pip install --upgrade pip 20 python -m pip install --upgrade pip
20 pip install -r requirements.txt 21 pip install -r requirements.txt
21 pip install pylint 22 - name: Install Ruff
22 - name: Analysing the code with pylint 23 uses: astral-sh/ruff-action@v3.2.2
24 - name: Ruff Actions
23 run: | 25 run: |
24 pylint -d R0801 -d W0311 -d R0914 $(git ls-files '*.py')\ No newline at end of file 26 ruff check --fix
27 ruff format
28 - name: Add and Commit
29 uses: EndBug/add-and-commit@v9
30 env:
31 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 with:
33 default_author: github_actions
34 pathspec_error_handling: ignore
nba/__main__.py +1
@@ -4,4 +4,5 @@ Entry point for the app.
4 4
5if __name__ == "__main__": 5if __name__ == "__main__":
6 from nba.cli import nba 6 from nba.cli import nba
7
7 nba() 8 nba()
nba/cli.py +18 −14
@@ -3,23 +3,27 @@ This script uses argparse to parse command line arguments.
3 3
4It imports the required modules and sets up a parser with basic options for demonstration purposes. 4It imports the required modules and sets up a parser with basic options for demonstration purposes.
5""" 5"""
6
6import argparse 7import argparse
7from nba import fetch_data, scores, standings 8from nba import fetch_data, scores, standings
8 9
10
9def nba() -> None: 11def nba() -> None:
10 """ 12 """
11 Parse command-line arguments and display either scoreboard or standings. 13 Parse command-line arguments and display either scoreboard or standings.
12 """ 14 """
13 parser = argparse.ArgumentParser(description="NBA Scoreboard and Standings") 15 parser = argparse.ArgumentParser(description="NBA Scoreboard and Standings")
14 parser.add_argument('--scores', '-sc', action='store_true', help='Display the scoreboard') 16 parser.add_argument("--scores", action="store_true", help="Display the scoreboard")
15 parser.add_argument('--standings', '-st', action='store_true', help='Display the standings') 17 parser.add_argument(
16 args = parser.parse_args() 18 "--standings", action="store_true", help="Display the standings"
19 )
20 args = parser.parse_args()
17 21
18 games, ranks = fetch_data.fetch_data() 22 games, ranks = fetch_data.fetch_data()
19 23
20 if args.scores: 24 if args.scores:
21 scores.build_scoreboard(games, ranks) 25 scores.build_scoreboard(games, ranks)
22 elif args.standings: 26 elif args.standings:
23 standings.build_standings(ranks) 27 standings.build_standings(ranks)
24 else: 28 else:
25 print("Please specify --scores or --standings") 29 print("Please specify --scores or --standings")
nba/fetch_data.py +18 −16
@@ -1,28 +1,30 @@
1""" 1"""
2Fetches data for use in other modules. 2Fetches data for use in other modules.
3""" 3"""
4
4import json 5import json
5from nba_api.live.nba.endpoints import scoreboard 6from nba_api.live.nba.endpoints import scoreboard
6from nba_api.stats.endpoints import leaguestandings 7from nba_api.stats.endpoints import leaguestandings
7 8
9
8def fetch_data() -> tuple: 10def fetch_data() -> tuple:
9 """ 11 """
10 Fetches live NBA scoreboard data and standings from the NBA API. 12 Fetches live NBA scoreboard data and standings from the NBA API.
11 13
12 Returns: 14 Returns:
13 games (dict): JSON parsed games data. 15 games (dict): JSON parsed games data.
14 standings (dict): JSON parsed team standings data. 16 standings (dict): JSON parsed team standings data.
15 """ 17 """
16 # Get today's scoreboard data 18 # Get today's scoreboard data
17 games_endpoint = scoreboard.ScoreBoard() 19 games_endpoint = scoreboard.ScoreBoard()
18 games_json = games_endpoint.get_json() 20 games_json = games_endpoint.get_json()
19 21
20 # Get league standings 22 # Get league standings
21 standings_endpoint = leaguestandings.LeagueStandings() 23 standings_endpoint = leaguestandings.LeagueStandings()
22 standings_json = standings_endpoint.get_json() 24 standings_json = standings_endpoint.get_json()
23 25
24 # Parse the JSON strings into Python dictionaries 26 # Parse the JSON strings into Python dictionaries
25 games = json.loads(games_json) 27 games = json.loads(games_json)
26 standings = json.loads(standings_json) 28 standings = json.loads(standings_json)
27 29
28 return games, standings 30 return games, standings
nba/scores.py +79 −74
@@ -1,85 +1,90 @@
1""" 1"""
2Tabulates a scoreboard for today's games. 2Tabulates a scoreboard for today's games.
3""" 3"""
4
4from tabulate import tabulate 5from tabulate import tabulate
5 6
6# ANSI escape codes for text formatting 7# ANSI escape codes for text formatting
7BOLD = '\033[1m' 8BOLD = "\033[1m"
8END = '\033[0m' 9END = "\033[0m"
9RED = '\033[91m' 10RED = "\033[91m"
10GREEN = '\033[32m' 11GREEN = "\033[32m"
12
11 13
12# Function to get team record from standings 14# Function to get team record from standings
13def get_team_record(team_name, standings) -> str: 15def get_team_record(team_name, standings) -> str:
14 """ 16 """
15 Retrieves a team's win-loss record from the standings data. 17 Retrieves a team's win-loss record from the standings data.
16 18
17 Args: 19 Args:
18 team_name (str): Name of the team. 20 team_name (str): Name of the team.
19 standings (dict): Team standings data. 21 standings (dict): Team standings data.
20 22
21 Returns: 23 Returns:
22 record (str): Team's win-loss record in 'W-L' format. Defaults to 'N/A'. 24 record (str): Team's win-loss record in 'W-L' format. Defaults to 'N/A'.
23 """ 25 """
24 for result_set in standings['resultSets']: 26 for result_set in standings["resultSets"]:
25 if result_set['name'] == 'Standings': 27 if result_set["name"] == "Standings":
26 for team in result_set['rowSet']: 28 for team in result_set["rowSet"]:
27 if team[4] == team_name: 29 if team[4] == team_name:
28 return f"{team[12]}-{team[13]}" 30 return f"{team[12]}-{team[13]}"
29 return "N/A" 31 return "N/A"
32
30 33
31def build_scoreboard(games, standings) -> None: 34def build_scoreboard(games, standings) -> None:
32 """ 35 """
33 Prints the current day's games in a table format. 36 Prints the current day's games in a table format.
34 37
35 Args: 38 Args:
36 games (dict): JSON parsed games data. 39 games (dict): JSON parsed games data.
37 standings (dict): Team standings data. 40 standings (dict): Team standings data.
38 """ 41 """
39 scoreboard_data = games['scoreboard'] 42 scoreboard_data = games["scoreboard"]
40 games = scoreboard_data['games'] 43 games = scoreboard_data["games"]
41 44
42 # Prepare the table data 45 # Prepare the table data
43 table_data = [] 46 table_data = []
44 for game in games: 47 for game in games:
45 home_team = game['homeTeam']['teamName'] 48 home_team = game["homeTeam"]["teamName"]
46 away_team = game['awayTeam']['teamName'] 49 away_team = game["awayTeam"]["teamName"]
47 game_status = game['gameStatusText'] 50 game_status = game["gameStatusText"]
48 home_score = game['homeTeam']['score'] 51 home_score = game["homeTeam"]["score"]
49 away_score = game['awayTeam']['score'] 52 away_score = game["awayTeam"]["score"]
50 53
51 home_record = get_team_record(home_team, standings) 54 home_record = get_team_record(home_team, standings)
52 away_record = get_team_record(away_team, standings) 55 away_record = get_team_record(away_team, standings)
53 56
54 # Determine the winning team 57 # Determine the winning team
55 if home_score > away_score: 58 if home_score > away_score:
56 home_team_bold = f"{BOLD}{GREEN}{home_team} ({home_record}){END}{END}" 59 home_team_bold = f"{BOLD}{GREEN}{home_team} ({home_record}){END}{END}"
57 away_team_bold = f"{away_team} ({away_record}){END}" 60 away_team_bold = f"{away_team} ({away_record}){END}"
58 home_score_bold = f"{BOLD}{GREEN}{home_score}{END}{END}" 61 home_score_bold = f"{BOLD}{GREEN}{home_score}{END}{END}"
59 away_score_bold = f"{away_score}{END}" 62 away_score_bold = f"{away_score}{END}"
60 elif away_score > home_score: 63 elif away_score > home_score:
61 home_team_bold = f"{home_team} ({home_record}){END}" 64 home_team_bold = f"{home_team} ({home_record}){END}"
62 away_team_bold = f"{BOLD}{GREEN}{away_team} ({away_record}){END}{END}" 65 away_team_bold = f"{BOLD}{GREEN}{away_team} ({away_record}){END}{END}"
63 home_score_bold = f"{home_score}{END}" 66 home_score_bold = f"{home_score}{END}"
64 away_score_bold = f"{BOLD}{GREEN}{away_score}{END}{END}" 67 away_score_bold = f"{BOLD}{GREEN}{away_score}{END}{END}"
65 else: 68 else:
66 home_team_bold = f"{home_team} ({home_record})" 69 home_team_bold = f"{home_team} ({home_record})"
67 away_team_bold = f"{away_team} ({away_record})" 70 away_team_bold = f"{away_team} ({away_record})"
68 home_score_bold = f"{home_score}" 71 home_score_bold = f"{home_score}"
69 away_score_bold = f"{away_score}" 72 away_score_bold = f"{away_score}"
70 73
71 # Determine games still in progress 74 # Determine games still in progress
72 if game_status != "Final": 75 if game_status != "Final":
73 game_status = f"{RED}{game_status}{END}" 76 game_status = f"{RED}{game_status}{END}"
74 77
75 table_data.append([ 78 table_data.append(
76 f"{home_team_bold}\n{away_team_bold}", 79 [
77 f"{home_score_bold}\n{away_score_bold}", 80 f"{home_team_bold}\n{away_team_bold}",
78 f"{BOLD}{game_status}{END}" 81 f"{home_score_bold}\n{away_score_bold}",
79 ]) 82 f"{BOLD}{game_status}{END}",
80 83 ]
81 # Define the table headers 84 )
82 headers = ["Team", "Score", "Game Status"] 85
83 86 # Define the table headers
84 # Print the table 87 headers = ["Team", "Score", "Game Status"]
85 print(tabulate(table_data, headers=headers, tablefmt="grid")) 88
89 # Print the table
90 print(tabulate(table_data, headers=headers, tablefmt="grid"))
nba/standings.py +68 −62
@@ -1,77 +1,83 @@
1""" 1"""
2Tabulate the current conference standings. 2Tabulate the current conference standings.
3""" 3"""
4
4from tabulate import tabulate 5from tabulate import tabulate
5 6
6# ANSI escape codes for text formatting 7# ANSI escape codes for text formatting
7BOLD = '\033[1m' 8BOLD = "\033[1m"
8END = '\033[0m' 9END = "\033[0m"
9RED = '\033[91m' 10RED = "\033[91m"
10GREEN = '\033[32m' 11GREEN = "\033[32m"
12
11 13
12def build_standings(standings) -> None: 14def build_standings(standings) -> None:
13 """ 15 """
14 Prints team standings in two separate tables. 16 Prints team standings in two separate tables.
15 17
16 Args: 18 Args:
17 standings (dict): Team standings data. 19 standings (dict): Team standings data.
18 """ 20 """
19 eastern_data = [] 21 eastern_data = []
20 western_data = [] 22 western_data = []
21 eastern_rank = 1 23 eastern_rank = 1
22 western_rank = 1 24 western_rank = 1
23 25
24 for result_set in standings['resultSets']: 26 for result_set in standings["resultSets"]:
25 if result_set['name'] == 'Standings': 27 if result_set["name"] == "Standings":
26 for team in result_set['rowSet']: 28 for team in result_set["rowSet"]:
27 conference = team[5] 29 conference = team[5]
28 team_name = team[4] 30 team_name = team[4]
29 wins = team[12] 31 wins = team[12]
30 losses = team[13] 32 losses = team[13]
31 win_pct = team[14] 33 win_pct = team[14]
32 gb = team[37] 34 gb = team[37]
33 home_record = team[17] 35 home_record = team[17]
34 away_record = team[18] 36 away_record = team[18]
35 last_10 = team[19] 37 last_10 = team[19]
36 streak = team[35] 38 streak = team[35]
37 39
38 if int(streak) < 0: 40 if int(streak) < 0:
39 strk_color = f"{RED}{streak}{END}" 41 strk_color = f"{RED}{streak}{END}"
40 else: 42 else:
41 strk_color = f"{GREEN}{streak}{END}" 43 strk_color = f"{GREEN}{streak}{END}"
42 44
43 if conference == "East": 45 if conference == "East":
44 eastern_data.append([ 46 eastern_data.append(
45 f"{eastern_rank}", 47 [
46 f"{team_name}", 48 f"{eastern_rank}",
47 f"{wins}-{losses}", 49 f"{team_name}",
48 f"{win_pct:.3f}", 50 f"{wins}-{losses}",
49 f"{gb}", 51 f"{win_pct:.3f}",
50 f"{strk_color}", 52 f"{gb}",
51 f"{last_10}", 53 f"{strk_color}",
52 f"{home_record}", 54 f"{last_10}",
53 f"{away_record}" 55 f"{home_record}",
54 ]) 56 f"{away_record}",
55 eastern_rank += 1 57 ]
56 elif conference == "West": 58 )
57 western_data.append([ 59 eastern_rank += 1
58 f"{western_rank}", 60 elif conference == "West":
59 f"{team_name}", 61 western_data.append(
60 f"{wins}-{losses}", 62 [
61 f"{win_pct:.3f}", 63 f"{western_rank}",
62 f"{gb}", 64 f"{team_name}",
63 f"{strk_color}", 65 f"{wins}-{losses}",
64 f"{last_10}", 66 f"{win_pct:.3f}",
65 f"{home_record}", 67 f"{gb}",
66 f"{away_record}" 68 f"{strk_color}",
67 ]) 69 f"{last_10}",
68 western_rank += 1 70 f"{home_record}",
71 f"{away_record}",
72 ]
73 )
74 western_rank += 1
69 75
70 headers = ["Rank", "Team", "W-L", "PCT", "GB", "STRK", "L10", "HOME", "AWAY"] 76 headers = ["Rank", "Team", "W-L", "PCT", "GB", "STRK", "L10", "HOME", "AWAY"]
71 77
72 print(f"{BOLD}Eastern Conference Standings:{END}") 78 print(f"{BOLD}Eastern Conference Standings:{END}")
73 print(tabulate(eastern_data, headers=headers, tablefmt="grid")) 79 print(tabulate(eastern_data, headers=headers, tablefmt="grid"))
74 80
75 print("\n") 81 print("\n")
76 print(f"{BOLD}Western Conference Standings:{END}") 82 print(f"{BOLD}Western Conference Standings:{END}")
77 print(tabulate(western_data, headers=headers, tablefmt="grid")) 83 print(tabulate(western_data, headers=headers, tablefmt="grid"))