def GetActivePlayers(self, season): # If the player list is empty, go retrieve the lastest list if (self.LastUpdateDateTime == time.gmtime(0)): log.info('Reloading Players') self.GetAllPlayers() # Get the latest list of eligible players url = COnfig.URL_roster soup = Config.GetHTMLSoup(url) x = soup.find_all(class_="table_1a")
def GetAllPlayers(self): self.Players = [] url = Config.URL_player soup = Config.GetHTMLSoup(url) playerHTML = soup.find_all('option') for index, x in enumerate(playerHTML): if (index < 3): continue id_str = x.get('value') player_name = x.get_text() try: player_id = int(id_str) if (player_name != ''): newPlayer = Player(player_id, player_name) self.Players.append(newPlayer) except: log.warning('Failed to convert') continue self.LastUpdateDateTime = datetime.datetime.now() self.Size = len(self.Players) log.info('Found %d players' % (self.Size))
class GameStat: log.info('Under Construction')
def GetStatsByPosition(self, position): if (position == Positions.Center): url = self.URL + '&filter_pos=center' elif (position == Positions.Wing): url = self.URL + '&filter_pos=wing' elif (position == Positions.Defense): url = self.URL + '&filter_pos=defense' elif (position == Positions.Goalie): url = self.URL + '&filter_pos=goalie' else: log.warning( 'Position entered that is not in the Config.Positions ENUM') soup = Config.GetHTMLSoup(url) tags = soup.find_all(class_="table_1")[0] #loop through all tags for index, tag in enumerate(tags): #clean all variables eligible = False #skip all empty tags if (tag != '\n'): log.info('Tag #%s - Length = %s' % (index, len(tag))) #only grab the first detailed contents and size row = tag.contents[1].get_text().splitlines() rowlen = len(row) log.info('Row Length = %s' % (len(row))) log.info(row) #find their position if (rowlen == 1 and 'Statistics' in row[0]): #Get their position pos = row[0].replace(' Statistics', '') elif (rowlen >= 20 and 'Season' in row[2]): log.info('Season Eligible') eligible = True season = row[2][7:] SeasonType = 'Regular' gp = row[5] g = row[6] a = row[7] pim = row[9] hits = row[10] shots = row[11] gwg = row[12] fop = row[13] pm = row[14] corsi = row[15] w = row[16] l = row[17] otl = row[18] sal = row[20].replace('$', '').replace(',', '') elif (rowlen >= 17 and 'Playoffs' in row[2]): log.info('Playoff Eligible') eligible = True SeasonType = 'Playoff' gp = row[4] g = row[5] a = row[6] pim = row[7] hits = row[8] shots = row[9] gwg = row[10] fop = row[11] pm = row[12] corsi = row[13] w = row[14] l = row[15] otl = row[16] sal = sal elif (rowlen >= 19 and 'International' in row[2]): log.info('International Eligible') eligible = True SeasonType = 'International' gp = row[4] g = row[5] a = row[6] pim = row[7] hits = row[8] shots = row[9] gwg = row[10] fop = row[11] pm = row[12] corsi = row[13] w = row[14] l = row[15] otl = row[16] sal = sal else: log.info('Not Eligible') if (eligible): newSeasonStat = PlayerSeasonStat(self.PID, self.Name, pos, season, SeasonType, gp, g, a, pim, hits, shots, gwg, fop, pm, corsi, w, l, otl, sal) row = pd.Series(newSeasonStat.ToList(), self.Columns) self.Stats.loc[len(self.Stats)] = row log.info(self.Stats)
def GetStatsForGoalie(self): log.info('Under Construction')
def GetStatsForDefense(self): log.info('Under Construction')
def GetStatsForWing(self): log.info('Under Construction')
def GetStatsForCenter(self): log.info('Under Construction')
def GetPlayerDetails(self): log.info("Extracting data for: %s (%s)" % (self.Name, self.PID)) url_player = Config.GetPlayerURL(self.PID) soup = Config.GetHTMLSoup(url_player) return soup
def GetOwners(self, season): # DO STUFF HERE log.info('GetOwners is being built')