def __init__(self): tid = ats.TeamIDs() team = tss.Season(tid.teamids) #print(team.getfirstgamestats()) for games in team.getseasonstats(): for play in games: if play[0] == 'Rush': pass #print(play) #input() #print(team.gameinseason[0].plays[0]) #print(team.gameinseason[0].ply[0].yards) player = "Trey Edmunds" # player = input('What player? ') self.yardhist = [] for x in range(len(team.gameinseason)): for y in range(len(team.gameinseason[x].ply)): if player == "TEAM": print("team ", team.gameinseason[x].ply[y].team.lower(), " offense ", team.gameinseason[x].ply[y].offense.lower(), "\n") if muf.is_abbrev(team.gameinseason[x].ply[y].offense.lower(), team.gameinseason[x].ply[y].team.lower()): self.yardhist.append([team.gameinseason[x].ply[y].yards]) else: if team.gameinseason[x].ply[y].runner.lower() == player.lower(): self.yardhist.append([team.gameinseason[x].ply[y].yards])
def __init__(self, gameid, teamname, season): #http://espn.go.com/ncf/playbyplay?gameId=292620259&period=0 # url = 'http://espn.go.com/ncf/playbyplay?gameId=' + gameid + '&period=0' #apparent update to format #http://espn.go.com/college-football/playbyplay?gameId=242410259 url = 'http://espn.go.com/ncf/playbyplay?gameId=' + gameid soup = muf.cleanhtml(url) game_pbp = "" self.teamname = "" self.opponent = "" self.season = season #title from the ESPN page, which typically includes both team names in full, plus game date # <title>Western Michigan Broncos vs. Virginia Tech Hokies - Play By Play - September 27, 2014 - ESPN</title> self.game_title = "" self.home = None for title in soup.findAll("title"): titletxt = title.get_text() team1 = titletxt[:titletxt.find(' v')] team2 = titletxt[titletxt.find('.')+2:titletxt.find(' -')] #print(team1, " ", team2) if all(word in team1 for word in teamname.split()): self.teamname = team1 self.opponent = team2 self.home = False elif all(word in team2 for word in teamname.split()): self.teamname = team2 self.opponent = team1 self.home = True self.game_result = "" for game in soup.findAll("div", { "class" : "competitors" }): for team in game.findAll("tr"): for teams in team.findAll("td", { "class" : "team-name" }): #print('teams: ', teams) self.game_result += teams.get_text() + " " for scores in team.find_all("td", { "class" : "final-score" }): #print('scores: ', scores) self.game_result += scores.get_text() + " " #print('game_result: ', self.game_result) #list of team and opponents names and abbreviation that are likely to be used self.tmnmlist = [self.teamname] self.oppnmlist = [self.opponent] gameresultlist = self.game_result.split() #print('gameresultlist: ', gameresultlist) if len(gameresultlist)>4: while len(gameresultlist)>4: if not gameresultlist[0].isdigit() and not gameresultlist[1].isdigit(): gameresultlist[0] = gameresultlist[0] + " " + gameresultlist[1] gameresultlist.remove(gameresultlist[1]) elif not gameresultlist[2].isdigit() and not gameresultlist[3].isdigit(): gameresultlist[2] = gameresultlist[2] + " " + gameresultlist[3] gameresultlist.remove(gameresultlist[3]) if self.home: if muf.is_abbrev(gameresultlist[2], self.teamname) and muf.is_abbrev(gameresultlist[0], self.opponent): self.tmnmlist.append(gameresultlist[2]) self.oppnmlist.append(gameresultlist[0]) elif muf.is_abbrev(gameresultlist[2], self.opponent) and muf.is_abbrev(gameresultlist[0], self.teamname): self.oppnmlist.append(gameresultlist[2]) self.tmnmlist.append(gameresultlist[0]) elif muf.is_abbrev(gameresultlist[2], self.teamname) and not muf.is_abbrev(gameresultlist[2], self.opponent): self.tmnmlist.append(gameresultlist[2]) self.oppnmlist.append(gameresultlist[0]) elif muf.is_abbrev(gameresultlist[2], self.opponent) and not muf.is_abbrev(gameresultlist[2], self.teamname): self.oppnmlist.append(gameresultlist[2]) self.tmnmlist.append(gameresultlist[0]) elif muf.is_abbrev(gameresultlist[0], self.teamname) and not muf.is_abbrev(gameresultlist[0], self.opponent): self.tmnmlist.append(gameresultlist[0]) self.oppnmlist.append(gameresultlist[2]) elif muf.is_abbrev(gameresultlist[0], self.opponent) and not muf.is_abbrev(gameresultlist[0], self.teamname): self.oppnmlist.append(gameresultlist[0]) self.tmnmlist.append(gameresultlist[2]) else: print('could not make sense of abbrevs') else: if muf.is_abbrev(gameresultlist[2], self.opponent) and muf.is_abbrev(gameresultlist[0], self.teamname): self.tmnmlist.append(gameresultlist[0]) self.oppnmlist.append(gameresultlist[2]) elif muf.is_abbrev(gameresultlist[2], self.teamname) and muf.is_abbrev(gameresultlist[0], self.opponent): self.oppnmlist.append(gameresultlist[0]) self.tmnmlist.append(gameresultlist[2]) elif muf.is_abbrev(gameresultlist[2], self.opponent) and not muf.is_abbrev(gameresultlist[2], self.teamname): self.tmnmlist.append(gameresultlist[0]) self.oppnmlist.append(gameresultlist[2]) elif muf.is_abbrev(gameresultlist[2], self.teamname) and not muf.is_abbrev(gameresultlist[2], self.opponent): self.oppnmlist.append(gameresultlist[0]) self.tmnmlist.append(gameresultlist[2]) elif muf.is_abbrev(gameresultlist[0], self.opponent) and not muf.is_abbrev(gameresultlist[0], self.teamname): self.tmnmlist.append(gameresultlist[2]) self.oppnmlist.append(gameresultlist[0]) elif muf.is_abbrev(gameresultlist[0], self.teamname) and not muf.is_abbrev(gameresultlist[0], self.opponent): self.oppnmlist.append(gameresultlist[2]) self.tmnmlist.append(gameresultlist[0]) else: print('could not make sense of abbrevs') #pbps is a data container for each string from ESPNs playbyplay file #which should include information about the quarter, drive, etc, in addition #to the actual play data self.pbps = [] #plays is a structure to store the actual play data, includeing all relevent #data about the current state of the game self.plays = [] self.ply = [] #here are my local variables for keeping track of game state information (ie quarter, drive, etc) gameperiod = 1 #1,2,3,4,5,6,7,8... etc, with 5 representing a first OT period, and so on drive = 1 possesion = self.teamname gamestate = {'quarter': gameperiod, 'driveno': drive, 'teamname': self.tmnmlist, 'opponent': self.oppnmlist, 'season': self.season, 'home':self.home, 'offense': possesion,} for gamestring in soup.findAll("div", { "id" : "gamepackage-play-by-play" }): game_pbp = gamestring for play in game_pbp.findAll("li"): print("play: ", play) self.pbps.append(play.get_text(separator=u'<>')) if 'Quarter' in self.pbps[-1]: if str(gameperiod) not in self.pbps[-1]: for char in self.pbps[-1]: if char.isdigit(): gameperiod = int(char) print(self.pbps[-1], " ", gameperiod) elif 'OT ' in self.pbps[-1]: gameperiod = self.isDigitOT(self.pbps[-1]) print(self.pbps[-1], " ", gameperiod) #if quarter or drive info, store to local variable, if play info, store info to plays, including quarter and drive info #play by play entries that still need to be dealt with elif any(word in self.pbps[-1] for word in ['coin toss', 'toss', 'kick', 'attempt failed', 'extra point', 'Extra Point', 'Extra point', 'Conversion', 'conversion', 'punt', 'FG', 'field goal', 'Field Goal', 'Penalty', 'PENALTY', 'penalty', 'Fumble']): pass #play by play entries I don't yet have plans for elif any(word in self.pbps[-1] for word in ['DRIVE', 'ball on', 'End']): pass #timeouts contain game clock info elif any(word in self.pbps[-1] for word in ['Timeout', 'timeout']): pass elif any(word in self.pbps[-1] for word in ['rush ', 'run ', 'Run ', 'sacked ', 'scramble ']): currentplay = plys.Rushing(self.pbps[-1], gamestate) self.plays.append(currentplay.getplayinfo()) self.ply.append(currentplay) elif any(word in self.pbps[-1] for word in ['pass ', 'incompletion ', 'interception ', 'Interception ']): currentplay = plys.Passing(self.pbps[-1], gamestate) self.plays.append(currentplay.getplayinfo()) elif any(word in self.pbps[-1] for word in ['SAFETY', 'Safety', 'safety']): pass elif any(word in self.pbps[-1] for word in [':']): #contains the team currently with the ball possesion = self.pbps[-1].split() while len(possesion)>1: if not possesion[0][0].isdigit() and not possesion[1][0].isdigit(): if possesion[1] == 'at': for n in range(len(possesion)-1): possesion.remove(possesion[1]) else: possesion[0] = possesion[0] + " " + possesion[1] possesion.remove(possesion[1]) else: possesion.remove(possesion[1]) #likely also containing the best game clock info for the game pass elif any(word in self.pbps[-1] for word in ['at','and']): #these might be empty plays due to inconsistencies and errors in espns play by play #may need to add some checks for this? pass else: #pass print("these are unhandled plays: ", self.pbps[-1]) gamestate['quarter'] = gameperiod gamestate['driveno'] = drive gamestate['offense'] = possesion
def __init__(self, pbpstring, gameinfo): self.pbptxt = pbpstring self.pbplist = pbpstring.split() #team refers to the team we've queriered, and not any one of their opponents over the year self.team = gameinfo['teamname'][0] self.teambrevs = gameinfo['teamname'] self.season = gameinfo['season'] self.opponent = gameinfo['opponent'][0] self.oppbrevs = gameinfo['opponent'] self.home = None #home bool value where true means the team we're #compiling data on is home and false means they are away if gameinfo['home']: self.home = True elif not gameinfo['home']: self.home = False #offensive team for all plays will be the team that will be playing offense #that is to say, offense = [kickoff return team, the offense, fieldgoal team, punt team, extra point team] #All values such as game number, will relate to the team that has been queried self.offense = str(gameinfo['offense'][0]) self.drive = None self.quarter = gameinfo['quarter'] self.gamenumber = None #penalty will be a bool. penalty plays can be of the class of play run, if the play was #actually run and recorder in the play-by-play, otherwise, they will be of class Penalty #must consider how to deal with "NO PLAY" "declined" or other possibilities self.penalty = False self.noplay = False if any(word in self.pbptxt for word in ['Penalty', 'PENALTY', 'penalty']): self.penalty = True if any(word in self.pbptxt for word in ['NO PLAY']): self.noplay = True self.distance = None self.down = None self.yardline = None print("pbpstring: ", pbpstring) if pbpstring[:1].isdigit() and (self.pbplist[2].isdigit() or self.pbplist[2] == 'Goal') and self.pbplist[5].isdigit(): self.down = int(pbpstring[:1]) self.distance = None if self.pbplist[2].isdigit(): self.distance = int(self.pbplist[2]) elif self.pbplist[2] == 'Goal': self.distance = 'Goal' else: self.distance = -1 #will measure yardline from 100-0, from offenses goal line (ie where a saftey is scored) #to opponents goal line (ie a touchdown is scored at the 0 yard line) #needs more robust checking, as checking for own/opp yardline is likly to fail on many sets of instate rivals right now self.yardline = None if muf.is_abbrev(self.pbplist[4], self.offense): self.yardline = 100-int(self.pbplist[5]) else: self.yardline = int(self.pbplist[5]) print(self.down, self.distance, self.yardline) else: #pass print("not getting down, dist, yrd") #add tracking of down dist yrdln from previous play results self.pointsscored = None self.currentscore = None