-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: v4
Are you sure you want to change the base?
Conversation
… return roster of team from that year
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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).
The related issue is #271 |
…nction. Also made season_end_year non-optional
… return roster of team from that year