Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions basketball_reference_web_scraper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def season_schedule(season_end_year, output_type=None, output_file_path=None, ou


def players_season_totals(season_end_year, output_type=None, output_file_path=None, output_write_option=None,
json_options=None):
json_options=None, include_combined_values=False):
try:
http_service = HTTPService(parser=ParserService())
values = http_service.players_season_totals(season_end_year=season_end_year)
values = http_service.players_season_totals(season_end_year=season_end_year, include_combined_values=include_combined_values)
except requests.exceptions.HTTPError as http_error:
if http_error.response.status_code == requests.codes.not_found:
raise InvalidSeason(season_end_year=season_end_year)
Expand Down
11 changes: 5 additions & 6 deletions basketball_reference_web_scraper/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def get_rows(self, include_combined_totals=False):
player_advanced_season_totals_rows = []
for row_html in self.html.xpath(self.rows_query):
row = PlayerAdvancedSeasonTotalsRow(html=row_html)
if (include_combined_totals is True and row.is_combined_totals is True) or row.is_combined_totals is False:
if (include_combined_totals and row.is_combined_totals) or not row.is_combined_totals:
# Basketball Reference includes a "total" row for players that got traded
# which is essentially a sum of all player team rows
# I want to avoid including those, so I check the "team" field value for "TOT"
# I want to avoid including those by default, so I check the "team" field value for "TOT"
player_advanced_season_totals_rows.append(row)

return player_advanced_season_totals_rows
Expand All @@ -291,15 +291,14 @@ def rows_query(self):
]
"""

@property
def rows(self):
def get_rows(self, include_combined_totals=False):
player_season_totals_rows = []
for row_html in self.html.xpath(self.rows_query):
row = PlayerSeasonTotalsRow(html=row_html)
# Basketball Reference includes a "total" row for players that got traded
# which is essentially a sum of all player team rows
# I want to avoid including those, so I check the "team" field value for "TOT"
if not row.is_combined_totals:
# I want to avoid including those by default, so I check the "team" field value for "TOT"
if not row.is_combined_totals or (row.is_combined_totals and include_combined_totals):
player_season_totals_rows.append(row)

return player_season_totals_rows
Expand Down
4 changes: 2 additions & 2 deletions basketball_reference_web_scraper/http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def players_advanced_season_totals(self, season_end_year, include_combined_value
table = PlayerAdvancedSeasonTotalsTable(html=html.fromstring(response.content))
return self.parser.parse_player_advanced_season_totals_parser(totals=table.get_rows(include_combined_values))

def players_season_totals(self, season_end_year):
def players_season_totals(self, season_end_year, include_combined_values=False):
url = '{BASE_URL}/leagues/NBA_{season_end_year}_totals.html'.format(
BASE_URL=HTTPService.BASE_URL,
season_end_year=season_end_year,
Expand All @@ -131,7 +131,7 @@ def players_season_totals(self, season_end_year):
response.raise_for_status()

table = PlayerSeasonTotalTable(html=html.fromstring(response.content))
return self.parser.parse_player_season_totals(totals=table.rows)
return self.parser.parse_player_season_totals(totals=table.get_rows(include_combined_values))

def schedule_for_month(self, url):
response = requests.get(url=url)
Expand Down