def boxscore_matchup(self, ast): if ast.phrase is None: raise Exception phrase = ast.phrase.lower() away_phrase, home_phrase = phrase.split(' at ') home_parts = home_phrase.split() parser = GameReportParser() # Try to parse date of form mm/dd/yyyy # Sometimes it's not present so we just skip it try: mdy = parser.parse(home_parts[-1], rule_name='mdy') except Exception: mdy = '' pass away = self.annual_team(away_phrase) home = self.annual_team(home_phrase) if away is None or home is None: raise Exception return AST(home=home, away=away, date=mdy)
def parse_league_daily(html, cities=None, nicknames=None): if cities is None or nicknames is None: raise Exception soup = BeautifulSoup(html, 'html.parser') tables = soup.find_all('table') semantics = GameReportSemanticActions(cities=cities, nicknames=nicknames) parser = GameReportParser(parseinfo=False, semantics=semantics) stories_ast = None for table in tables: try: stories_ast = parser.parse(table.prettify(), 'game_story_table') break except FailedParse: pass boxscores_ast = None for table in tables: try: boxscores_ast = parser.parse(table.prettify(), 'boxscore_table') break except FailedParse: pass if stories_ast is None or boxscores_ast is None: raise Exception return AST(game_stories=stories_ast, boxscores=boxscores_ast)
def parse_game_daily(html, cities=None, nicknames=None): soup = BeautifulSoup(html, 'html.parser') full_recap = soup.find('pre') full_recap_string = full_recap.prettify() semantics = GameReportSemanticActions(cities=cities, nicknames=nicknames) parser = GameReportParser(parseinfo=False, semantics=semantics) ast = parser.parse(full_recap_string, 'full_recap') return ast