def parse_matchup(matchup_data): matchup_table = matchup_data.find("table") team_rx = re.compile(".*college-football/teams/team-page.cfm/team.*") teams = matchup_table.findAll("a", href=team_rx) away_team, home_team = get_teams(teams) if away_team == None or home_team == None: #if we dont find a team go onto the next team matchup return matchup_date = None try: date_re = re.compile("date/(.*)") anchor_tag = matchup_table.find(href=date_re) matchup_date_str = date_re.search(anchor_tag['href']).group(1) matchup_date = datetime.datetime.strptime(matchup_date_str,"%m-%d-%y") except: logger.exception( "matchup date could not be found" ) logger.error( "anchor tag: " + str(anchor_tag ) ) logger.error( "matchup: " + matchup_table.prettify() ) return matchup = Matchup() insider_game_id = "%s-@-%s" % (away_team.name.replace(' ','-'), home_team.name.replace(' ','-')) found_matchups = Matchup.objects.filter(insider_game_id=insider_game_id, gametime=matchup_date, season=YEAR) if len(found_matchups) > 0: matchup = found_matchups[0] else: logger.info("!! could not find matchup for: " +insider_game_id + " and date: " + str(matchup_date_str) ) matchup.insider_game_id = insider_game_id matchup.gametime = matchup_date matchup.home_team = home_team matchup.away_team = away_team matchup.season = int(YEAR) get_lines_and_score( matchup, matchup_table ) logger.info("final score was: %s to %s for game: %s " % (str(matchup.away_score), str(matchup.home_score), matchup.insider_game_id) ) try: if not DEBUG: matchup.save() except: logger.exception("problem saving matchup for game id: " + matchup.insider_game_id) logger.exception("path: " + path) exit(1)
def parse_matchup(matchup_data): matchup_table = matchup_data.findParent("table") team_rx = re.compile(".*college-football/teams/team-page.cfm/team.*") teams = matchup_table.findAll("a", href=team_rx) away_team, home_team = get_teams(teams) if away_team == None or home_team == None: logger.error("couldn't find teams") logger.error(matchup_table) return date_re = re.compile("date/(.*?)/time") anchor_tag = matchup_table.find(href=date_re) matchup_date_str = date_re.search(anchor_tag['href']).group(1) matchup_date = time.strptime(matchup_date_str,"%m-%d-%y") matchup = Matchup() insider_game_id = "%s-@-%s" % (away_team.name.replace(' ','-'), home_team.name.replace(' ','-')) gametime = strftime("%Y-%m-%d", matchup_date) found_matchups = Matchup.objects.filter(insider_game_id=insider_game_id, gametime=gametime, season=year) if len(found_matchups) > 1: logger.error("!! there can't be more than one matchup for:%s and time %s",(insider_game_id, gametime)) if len(found_matchups) == 1: matchup = found_matchups[0] matchup.insider_game_id = insider_game_id matchup.gametime = gametime matchup.home_team = home_team matchup.away_team = away_team matchup.season = year get_lines( matchup, matchup_table ) try: matchup.save() except: logger.exception("problem saving matchup for game id: " + matchup.insider_game_id) exit(1)