Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_roster function that takes in team abbreviation and year to… #276

Open
wants to merge 2 commits into
base: v4
Choose a base branch
from

Conversation

PGatts
Copy link

@PGatts PGatts commented Oct 1, 2024

… return roster of team from that year

Copy link
Owner

@jaebradley jaebradley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PGatts sorry for the delayed review!

This is a cool feature to add - hopefully my feedback makes sense!

@@ -1,4 +1,6 @@
#!/Users/jaebradley/projects/basketball_reference_web_scraper/bin/python3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PGatts these bin files should never have been committed - I removed them in 81dd1e0

Rebasing / merging the latest changes in v4 should resolve the merge conflicts caused by the bin directory.

@@ -212,6 +212,35 @@ def team_box_scores(day, month, year, output_type=None, output_file_path=None, o
)
return output_service.output(data=values, options=options)

def get_roster(team, year=None, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make year a non-optional argument. I don't think there's a pattern for any year values being optional (intentionally).

@@ -212,6 +212,35 @@ def team_box_scores(day, month, year, output_type=None, output_file_path=None, o
)
return output_service.output(data=values, options=options)

def get_roster(team, year=None, output_type=None, output_file_path=None, output_write_option=None, json_options=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we rename year to season_end_year? Following the naming convention in similar season-related methods.

values=http_service.get_team_roster(team=team, year=year)
except requests.exceptions.HTTPError as http_error:
if http_error.response.status_code == requests.codes.not_found:
raise InvalidTeam(team=team, year=year)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error's name is slightly inaccurate - the team value could be valid, but the season end year value could be invalid, like https://www.basketball-reference.com/teams/BOS/1020.html

I'd prefer to call this error InvalidTeamSeason (or something similar).

(Note that I've made similar inaccurate naming mistakes in other methods, like InvalidDate, that need to be corrected in the future.)

file_options=FileOptions.of(path=output_file_path, mode=output_write_option),
output_type=output_type,
json_options=json_options,
csv_options={"column_names": "Players"}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the Roster table

image

Happy to add more values in the future, but at a minimum the values should be

  • name
  • slug (or player_id)

@@ -870,6 +870,17 @@ def game_url_paths(self):
game_links = self.html.xpath(self.game_url_paths_query)
return [game_link.attrib['href'] for game_link in game_links]

class TeamRoster:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a SeasonTeamPage class that has a property called @team_roster_table?

Most of all the client methods refer to a top-level Page class that might expose underlying tables with properties or methods.

@property
def roster_query(self):
return '//table[@id="roster"]//td[@data-stat="player"]'
@property
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's have a new line between lines 879 and 880.

def roster_query(self):
return '//table[@id="roster"]//td[@data-stat="player"]'
@property
def team_roster(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create Row classes to represent the underlying row content (to keep consistent with similar patterns in this file).

@jaebradley
Copy link
Owner

The related issue is #271

…nction. Also made season_end_year non-optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants