コード例 #1
0
def regular_season_player_box_scores(player_identifier,
                                     season_end_year,
                                     output_type=None,
                                     output_file_path=None,
                                     output_write_option=None,
                                     json_options=None):
    try:
        http_service = HTTPService(parser=ParserService())
        values = http_service.regular_season_player_box_scores(
            player_identifier=player_identifier,
            season_end_year=season_end_year,
        )
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.internal_server_error \
                or http_error.response.status_code == requests.codes.not_found:
            raise InvalidPlayerAndSeason(player_identifier=player_identifier,
                                         season_end_year=season_end_year)
        else:
            raise http_error
    options = OutputOptions.of(
        file_options=FileOptions.of(path=output_file_path,
                                    mode=output_write_option),
        output_type=output_type,
        json_options=json_options,
        csv_options={"column_names": PLAYER_SEASON_BOX_SCORE_COLUMN_NAMES})
    output_service = OutputService(
        json_writer=JSONWriter(value_formatter=BasketballReferenceJSONEncoder),
        csv_writer=CSVWriter(value_formatter=format_value))
    return output_service.output(data=values, options=options)
コード例 #2
0
def regular_season_player_box_scores(player_identifier,
                                     season_end_year,
                                     output_type=None,
                                     output_file_path=None,
                                     output_write_option=None,
                                     json_options=None):

    try:
        http_service = HTTPService(parser=ParserService())
        values = http_service.regular_season_player_box_scores(
            player_identifier=player_identifier,
            season_end_year=season_end_year,
        )
    except requests.exceptions.HTTPError as http_error:
        if http_error.response.status_code == requests.codes.internal_server_error \
                or http_error.response.status_code == requests.codes.not_found:
            raise InvalidPlayerAndSeason(player_identifier=player_identifier,
                                         season_end_year=season_end_year)
        else:
            raise http_error
    return output(
        values=values,
        output_type=output_type,
        output_file_path=output_file_path,
        output_write_option=output_write_option,
        csv_writer=CSVWriter(
            column_names=PLAYER_SEASON_BOX_SCORE_COLUMN_NAMES,
            row_formatter=RowFormatter(
                data_field_names=PLAYER_SEASON_BOX_SCORE_COLUMN_NAMES)),
        json_options=json_options,
    )
コード例 #3
0
def regular_season_player_box_scores(player_identifier, season_end_year):
    # Makes assumption that basketball reference pattern of breaking out player pathing using first character of
    # surname can be derived from the fact that basketball reference also has a pattern of player identifiers
    # starting with first few characters of player's surname
    url = '{BASE_URL}/players/{player_surname_starting_character}/{player_identifier}/gamelog/{season_end_year}'.format(
        BASE_URL=BASE_URL,
        player_surname_starting_character=player_identifier[0],
        player_identifier=player_identifier,
        season_end_year=season_end_year,
    )

    response = requests.get(url=url, allow_redirects=False)
    response.raise_for_status()

    page = PlayerSeasonBoxScoresPage(html=html.fromstring(response.content))
    if page.regular_season_box_scores_table is None:
        raise InvalidPlayerAndSeason(player_identifier=player_identifier,
                                     season_end_year=season_end_year)

    parser = PlayerSeasonBoxScoresParser(
        team_abbreviation_parser=TeamAbbreviationParser(
            abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM),
        location_abbreviation_parser=LocationAbbreviationParser(
            abbreviations_to_locations=LOCATION_ABBREVIATIONS_TO_POSITION),
        outcome_parser=PlayerBoxScoreOutcomeParser(
            outcome_abbreviation_parser=OutcomeAbbreviationParser(
                abbreviations_to_outcomes=OUTCOME_ABBREVIATIONS_TO_OUTCOME), ),
        seconds_played_parser=SecondsPlayedParser(),
    )
    return parser.parse(box_scores=page.regular_season_box_scores_table.rows)
コード例 #4
0
    def playoff_player_box_scores(self, player_identifier, season_end_year):
        # Makes assumption that basketball reference pattern of breaking out player pathing using first character of
        # surname can be derived from the fact that basketball reference also has a pattern of player identifiers
        # starting with first few characters of player's surname
        url = '{BASE_URL}/players/{player_surname_starting_character}/{player_identifier}/gamelog/{season_end_year}' \
            .format(
            BASE_URL=HTTPService.BASE_URL,
            player_surname_starting_character=player_identifier[0],
            player_identifier=player_identifier,
            season_end_year=season_end_year,
        )

        response = requests.get(url=url, allow_redirects=False)
        response.raise_for_status()

        page = PlayerSeasonBoxScoresPage(
            html=html.fromstring(response.content))
        if page.playoff_box_scores_table is None:
            raise InvalidPlayerAndSeason(player_identifier=player_identifier,
                                         season_end_year=season_end_year)

        return self.parser.parse_player_season_box_scores(
            box_scores=page.playoff_box_scores_table.rows)