def __init__(self):
        self.team_abbreviation_parser = TeamAbbreviationParser(abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM)
        self.location_abbreviation_parser = LocationAbbreviationParser(
            abbreviations_to_locations=LOCATION_ABBREVIATIONS_TO_POSITION,
        )
        self.outcome_abbreviation_parser = OutcomeAbbreviationParser(
            abbreviations_to_outcomes=OUTCOME_ABBREVIATIONS_TO_OUTCOME,
        )
        self.outcome_parser = PlayerBoxScoreOutcomeParser(outcome_abbreviation_parser=self.outcome_abbreviation_parser)
        self.position_abbreviation_parser = PositionAbbreviationParser(
            abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION,
        )
        self.seconds_played_parser = SecondsPlayedParser()

        self.player_box_scores_parser = PlayerBoxScoresParser(
            team_abbreviation_parser=self.team_abbreviation_parser,
            location_abbreviation_parser=self.location_abbreviation_parser,
            outcome_abbreviation_parser=self.outcome_abbreviation_parser,
            seconds_played_parser=self.seconds_played_parser
        )
        self.player_season_box_scores_parser = PlayerSeasonBoxScoresParser(
            team_abbreviation_parser=self.team_abbreviation_parser,
            location_abbreviation_parser=self.location_abbreviation_parser,
            outcome_parser=self.outcome_parser,
            seconds_played_parser=self.seconds_played_parser
        )
        self.player_season_totals_parser = PlayerSeasonTotalsParser(
            position_abbreviation_parser=self.position_abbreviation_parser,
            team_abbreviation_parser=self.team_abbreviation_parser,
        )
def player_box_scores(day, month, year):
    url = '{BASE_URL}/friv/dailyleaders.cgi?month={month}&day={day}&year={year}'.format(
        BASE_URL=BASE_URL,
        day=day,
        month=month,
        year=year
    )

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

    response.raise_for_status()

    if response.status_code == requests.codes.ok:
        page = DailyLeadersPage(html=html.fromstring(response.content))
        box_score_parser = PlayerBoxScoresParser(
            team_abbreviation_parser=TeamAbbreviationParser(
                abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM
            ),
            location_abbreviation_parser=LocationAbbreviationParser(
                abbreviations_to_locations=LOCATION_ABBREVIATIONS_TO_POSITION
            ),
            outcome_abbreviation_parser=OutcomeAbbreviationParser(
                abbreviations_to_outcomes=OUTCOME_ABBREVIATIONS_TO_OUTCOME
            ),
            seconds_played_parser=SecondsPlayedParser(),
        )
        return box_score_parser.parse(page.daily_leaders)

    raise InvalidDate(day=day, month=month, year=year)
Esempio n. 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)
 def setUp(self):
     self.season_2001_totals = requests.get(
         'https://www.basketball-reference.com/leagues/NBA_2001_totals.html'
     ).text
     self.season_2018_totals = requests.get(
         'https://www.basketball-reference.com/leagues/NBA_2018_totals.html'
     ).text
     self.season_2019_totals = requests.get(
         'https://www.basketball-reference.com/leagues/NBA_2019_totals.html'
     ).text
     self.jemerrio_jones_blank_age_2019_totals_file = open(
         os.path.join(
             os.path.dirname(__file__),
             '../files/NBA_2019_totals_jemerrio_jones_blank_age.html',
         )
     )
     self.jemerrio_jones_with_a_blank_age_2019_totals = self.jemerrio_jones_blank_age_2019_totals_file.read()
     self.parser = PlayerSeasonTotalsParser(
         position_abbreviation_parser=PositionAbbreviationParser(
             abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION
         ),
         team_abbreviation_parser=TeamAbbreviationParser(
             abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM,
         )
     )
Esempio n. 5
0
 def setUp(self):
     self.november_01_2006_daily_leaders = requests.get(
         'https://www.basketball-reference.com/friv/dailyleaders.fcgi?month=11&day=1&year=2006'
     ).text
     self.december_18_2015_daily_leaders = requests.get(
         'https://www.basketball-reference.com/friv/dailyleaders.fcgi?month=12&day=18&year=2015'
     ).text
     self.november_03_2003_daily_leaders = requests.get(
         'https://www.basketball-reference.com/friv/dailyleaders.fcgi?month=11&day=03&year=2003'
     ).text
     self.december_12_2017_daily_leaders = requests.get(
         'https://www.basketball-reference.com/friv/dailyleaders.fcgi?month=12&day=12&year=2017'
     ).text
     self.january_29_2017_daily_leaders = requests.get(
         'https://www.basketball-reference.com/friv/dailyleaders.fcgi?month=1&day=29&year=2017'
     ).text
     self.team_abbreviation_parser = TeamAbbreviationParser(
         abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM)
     self.location_abbreviation_parser = LocationAbbreviationParser(
         abbreviations_to_locations=LOCATION_ABBREVIATIONS_TO_POSITION)
     self.outcome_abbreviation_parser = OutcomeAbbreviationParser(
         abbreviations_to_outcomes=OUTCOME_ABBREVIATIONS_TO_OUTCOME)
     self.seconds_played_parser = SecondsPlayedParser()
     self.player_box_scores_parser = PlayerBoxScoresParser(
         team_abbreviation_parser=self.team_abbreviation_parser,
         location_abbreviation_parser=self.location_abbreviation_parser,
         outcome_abbreviation_parser=self.outcome_abbreviation_parser,
         seconds_played_parser=self.seconds_played_parser,
     )
Esempio n. 6
0
 def setUp(self):
     self.season_2019_totals = requests.get(
         'https://www.basketball-reference.com/leagues/NBA_2019_advanced.html'
     ).text
     self.parser = PlayerAdvancedSeasonTotalsParser(
         position_abbreviation_parser=PositionAbbreviationParser(
             abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION
         ),
         team_abbreviation_parser=TeamAbbreviationParser(
             abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM,
         ),
     )
     self.season_2019_totals_table = PlayerAdvancedSeasonTotalsTable(html=html.fromstring(self.season_2019_totals))
Esempio n. 7
0
def players_season_totals(season_end_year):
    url = '{BASE_URL}/leagues/NBA_{season_end_year}_totals.html'.format(
        BASE_URL=BASE_URL,
        season_end_year=season_end_year,
    )

    response = requests.get(url=url)

    response.raise_for_status()

    table = PlayerSeasonTotalTable(html=html.fromstring(response.content))
    parser = PlayerSeasonTotalsParser(
        position_abbreviation_parser=PositionAbbreviationParser(
            abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION),
        team_abbreviation_parser=TeamAbbreviationParser(
            abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM, ))
    return parser.parse(table.rows)
 def setUp(self):
     self.atlanta_box_score_2017_01_01 = requests.get(
         'https://www.basketball-reference.com/boxscores/201701010ATL.html'
     ).text
     self.team_abbreviation_parser = TeamAbbreviationParser(
         abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM, )
     self.page = BoxScoresPage(
         html.fromstring(self.atlanta_box_score_2017_01_01))
     self.combined_team_totals = [
         TeamTotal(team_abbreviation=table.team_abbreviation,
                   totals=table.team_totals)
         for table in self.page.basic_statistics_tables
     ]
     self.parser = TeamTotalsParser(
         team_abbreviation_parser=self.team_abbreviation_parser)
     self.team_totals = self.parser.parse(
         first_team_totals=self.combined_team_totals[0],
         second_team_totals=self.combined_team_totals[1],
     )
def team_box_score(game_url_path):
    url = "{BASE_URL}/{game_url_path}".format(BASE_URL=BASE_URL, game_url_path=game_url_path)

    response = requests.get(url=url)

    response.raise_for_status()

    page = BoxScoresPage(html.fromstring(response.content))
    combined_team_totals = [
        TeamTotal(team_abbreviation=table.team_abbreviation, totals=table.team_totals)
        for table in page.basic_statistics_tables
    ]
    parser = TeamTotalsParser(team_abbreviation_parser=TeamAbbreviationParser(
        abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM,
    ))

    return parser.parse(
        first_team_totals=combined_team_totals[0],
        second_team_totals=combined_team_totals[1],
    )
def players_advanced_season_totals(season_end_year, include_combined_values=False):
    url = '{BASE_URL}/leagues/NBA_{season_end_year}_advanced.html'.format(
        BASE_URL=BASE_URL,
        season_end_year=season_end_year,
    )

    response = requests.get(url=url)

    response.raise_for_status()

    table = PlayerAdvancedSeasonTotalsTable(html=html.fromstring(response.content))
    parser = PlayerAdvancedSeasonTotalsParser(
        team_abbreviation_parser=TeamAbbreviationParser(
            abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM
        ),
        position_abbreviation_parser=PositionAbbreviationParser(
            abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION
        )
    )

    return parser.parse(table.get_rows(include_combined_values))
    def __init__(self):
        self.team_abbreviation_parser = TeamAbbreviationParser(
            abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM)
        self.league_abbreviation_parser = LeagueAbbreviationParser(
            abbreviations_to_league=LEAGUE_ABBREVIATIONS_TO_LEAGUE)
        self.location_abbreviation_parser = LocationAbbreviationParser(
            abbreviations_to_locations=LOCATION_ABBREVIATIONS_TO_POSITION, )
        self.outcome_abbreviation_parser = OutcomeAbbreviationParser(
            abbreviations_to_outcomes=OUTCOME_ABBREVIATIONS_TO_OUTCOME, )
        self.outcome_parser = PlayerBoxScoreOutcomeParser(
            outcome_abbreviation_parser=self.outcome_abbreviation_parser)
        self.period_details_parser = PeriodDetailsParser(
            regulation_periods_count=4)
        self.period_timestamp_parser = PeriodTimestampParser(
            timestamp_format=ParserService.PLAY_BY_PLAY_TIMESTAMP_FORMAT)
        self.position_abbreviation_parser = PositionAbbreviationParser(
            abbreviations_to_positions=POSITION_ABBREVIATIONS_TO_POSITION, )
        self.seconds_played_parser = SecondsPlayedParser()
        self.scores_parser = ScoresParser(
            scores_regex=ParserService.PLAY_BY_PLAY_SCORES_REGEX)
        self.search_result_name_parser = SearchResultNameParser()
        self.search_result_location_parser = ResourceLocationParser(
            resource_location_regex=ParserService.
            SEARCH_RESULT_RESOURCE_LOCATION_REGEX)
        self.team_name_parser = TeamNameParser(
            team_names_to_teams=TEAM_NAME_TO_TEAM)

        self.play_by_plays_parser = PlayByPlaysParser(
            period_details_parser=self.period_details_parser,
            period_timestamp_parser=self.period_timestamp_parser,
            scores_parser=self.scores_parser,
        )
        self.player_box_scores_parser = PlayerBoxScoresParser(
            team_abbreviation_parser=self.team_abbreviation_parser,
            location_abbreviation_parser=self.location_abbreviation_parser,
            outcome_abbreviation_parser=self.outcome_abbreviation_parser,
            seconds_played_parser=self.seconds_played_parser)
        self.player_data_parser = PlayerDataParser(
            search_result_location_parser=self.search_result_location_parser,
            league_abbreviation_parser=self.league_abbreviation_parser,
        )
        self.player_season_box_scores_parser = PlayerSeasonBoxScoresParser(
            team_abbreviation_parser=self.team_abbreviation_parser,
            location_abbreviation_parser=self.location_abbreviation_parser,
            outcome_parser=self.outcome_parser,
            seconds_played_parser=self.seconds_played_parser)
        self.player_season_totals_parser = PlayerSeasonTotalsParser(
            position_abbreviation_parser=self.position_abbreviation_parser,
            team_abbreviation_parser=self.team_abbreviation_parser,
        )
        self.player_advanced_season_totals_parser = PlayerAdvancedSeasonTotalsParser(
            team_abbreviation_parser=self.team_abbreviation_parser,
            position_abbreviation_parser=self.position_abbreviation_parser,
        )
        self.scheduled_start_time_parser = ScheduledStartTimeParser()
        self.scheduled_games_parser = ScheduledGamesParser(
            start_time_parser=self.scheduled_start_time_parser,
            team_name_parser=self.team_name_parser,
        )
        self.search_results_parser = SearchResultsParser(
            search_result_name_parser=self.search_result_name_parser,
            search_result_location_parser=self.search_result_location_parser,
            league_abbreviation_parser=self.league_abbreviation_parser,
        )
        self.team_totals_parser = TeamTotalsParser(
            team_abbreviation_parser=self.team_abbreviation_parser)
        self.division_name_parser = DivisionNameParser(divisions=Division)
        self.team_standings_parser = TeamStandingsParser(teams=Team)
        self.conference_division_standings_parser = ConferenceDivisionStandingsParser(
            division_name_parser=self.division_name_parser,
            team_standings_parser=self.team_standings_parser,
            divisions_to_conferences=DIVISIONS_TO_CONFERENCES,
        )
Esempio n. 12
0
 def setUp(self):
     self.parser = TeamTotalsParser(
         team_abbreviation_parser=TeamAbbreviationParser(
             abbreviations_to_teams=TEAM_ABBREVIATIONS_TO_TEAM))