def play_by_play(home_team, day, month, year): add_0_if_needed = lambda s: "0" + s if len(s) == 1 else s # the hard-coded `0` in the url assumes we always take the first match of the given date and team. url = "{BASE_URL}/boxscores/pbp/{year}{month}{day}0{team_abbr}.html".format( BASE_URL=BASE_URL, year=year, month=add_0_if_needed(str(month)), day=add_0_if_needed(str(day)), team_abbr=TEAM_TO_TEAM_ABBREVIATION[home_team]) response = requests.get(url=url) response.raise_for_status() page = PlayByPlayPage(html=html.fromstring(response.content)) play_by_plays_parser = PlayByPlaysParser( period_details_parser=PeriodDetailsParser(regulation_periods_count=4), period_timestamp_parser=PeriodTimestampParser( timestamp_format=PLAY_BY_PLAY_TIMESTAMP_FORMAT), scores_parser=ScoresParser(scores_regex=PLAY_BY_PLAY_SCORES_REGEX)) team_name_parser = TeamNameParser(team_names_to_teams=TEAM_NAME_TO_TEAM) return play_by_plays_parser.parse( play_by_plays=page.play_by_play_table.rows, away_team=team_name_parser.parse_team_name( team_name=page.away_team_name), home_team=team_name_parser.parse_team_name( team_name=page.home_team_name))
def play_by_play(self, home_team, day, month, year): add_0_if_needed = lambda s: "0" + s if len(s) == 1 else s # the hard-coded `0` in the url assumes we always take the first match of the given date and team. url = "{BASE_URL}/boxscores/pbp/{year}{month}{day}0{team_abbr}.html".format( BASE_URL=HTTPService.BASE_URL, year=year, month=add_0_if_needed(str(month)), day=add_0_if_needed(str(day)), team_abbr=TEAM_TO_TEAM_ABBREVIATION[home_team]) response = requests.get(url=url) response.raise_for_status() page = PlayByPlayPage(html=html.fromstring(response.content)) return self.parser.parse_play_by_plays( play_by_plays=page.play_by_play_table.rows, away_team_name=page.away_team_name, home_team_name=page.home_team_name, )