def mlb_edge_list(year): teams = [team.club.upper() for team in mlbgame.teams()] edge_list = [] edge_weights = {} games = mlbgame.combine_games(mlbgame.games(year)) team_dict = { team.club_common_name: team.club.upper() for team in mlbgame.teams() } for game in games: try: if str(game.w_team) not in team_dict or str( game.l_team) not in team_dict: continue w_team = team_dict[game.w_team] l_team = team_dict[game.l_team] if (str(w_team), str(l_team)) in edge_list: edge_weights[(str(w_team), str(l_team))] += 1 else: edge_weights[( str(w_team), str(l_team))] = 1 #abs(game.score_home-game.score_away) edge_list.append((str(w_team), str(l_team))) except AttributeError: pass new_edge_list = [] for winner, loser in edge_list: if (loser, winner) not in edge_weights or edge_weights[ (winner, loser)] > edge_weights[(loser, winner)]: new_edge_list.append((winner, loser)) return new_edge_list
def __init__(self,parent): #Init data grab self.teams = mlbgame.teams() self.standings = mlbgame.standings() #Init vars self.teamselect = StringVar(window) self.gamedate = StringVar(window) #Init navigation self.navigation() self.show_calendar()
def get_team_list(): list = teams() size = list.__len__() team_name_list = [] for team in list: # curTeam = team.club_full_name team_name_list.append(team.club_full_name) return team_name_list
def main(): # acts as main method cubsPlayers = [] teams = mlbgame.teams() # Grabs list of team objects for team in teams: # just to test for now if team.club_common_name == 'Cubs': id = team.team_id # print(id, team.club_common_name, team.division) count = 0 pid = 0 # for team in teams: for i in range(4, 11): year = mlbgame.games(2015, i, home='Cubs', away='Cubs') games = mlbgame.combine_games(year) for game in games: try: cubsGameStats = mlbgame.player_stats(game.game_id).home_batting for p in cubsGameStats: temp = p.name_display_first_last f, l = p.name_display_first_last.split() if not any(x.firstName + ' ' + x.lastName == temp for x in cubsPlayers): if p.pos == 'P': # is a pitcher #print(p.name_display_first_last, 'pitcher') pid += 1 #newPlayer = Pitcher(f, l, p.s_era) else: #print(p.name_display_first_last, p.pos, p.s_hr) pid += 1 newPlayer = Batter(f, l, p.s_hr) cubsPlayers.append(newPlayer) count += 1 #print(game, count) except ValueError: print('No game found') for p in cubsPlayers: print(p, p.hr) print(len(cubsPlayers))
def getMLBEdges(start, end, gamma=0.8): """ Generates a dictionary of (team1, team2) -> wl_spread where wl_spread is the sum of discounted win-loss spreads of seasons between start and end. Win-loss spreads are calculated as the number of wins team1 has against team2 minus the number of losses Args: start (int): the first season to gather data for end (int): the last season to collect data for gamma (float): the discount factor to apply to past seasons Returns: A dictionary of edges to win/loss spreads """ edges = {} teams = { team.club_common_name: team.club.upper() for team in mlbgame.teams() } for year in range(start, end + 1): if year not in mlbGames: games = mlbgame.combine_games(mlbgame.games(year)) mlbGames[year] = games else: games = mlbGames[year] discount = gamma**(end - year) for game in games: try: # Some game data is with teams not in the MLB, some games don't have winners, so check for that if game.w_team in teams and game.l_team in teams: winner = teams[game.w_team] loser = teams[game.l_team] edges[(winner, loser)] = edges.get( (winner, loser), 0.0) + 1 * discount edges[(loser, winner)] = edges.get( (loser, winner), 0.0) - 1 * discount except AttributeError: pass return teams.values(), edges
async def on_ready(): # call change_status method for rotating status change_status.start() # gather relevent information for commands # ! This step is due to the mlbgame wrapper being really slow. # ! So I start getting the information as soon as the bot goes online and run every 12 hours. # ! This should be enough for this bots functionality # ? I plan to improve this once I find a decent free real time api or mlb comes out with thier own :) # grab Braves team_id - not hard coding in case it changes teams = mlbgame.teams() for team in teams: if team.club_full_name == 'Atlanta Braves': braves_id = team.team_id print(f'Braves ID is {braves_id}') # log bot is running print(f'{bot.user.name} is ready...\n')
def getMLBGames(year): teams = { team.club_common_name: team.club.upper() for team in mlbgame.teams() } if year not in mlbGames: games = mlbgame.combine_games(mlbgame.games(year)) mlbGames[year] = games else: games = mlbGames[year] processedGames = [] for game in games: try: if game.w_team in teams and game.l_team in teams: winner = teams[game.w_team] loser = teams[game.l_team] processedGames.append((winner, loser)) except: pass return processedGames
def test_teams(self): teams = mlbgame.teams() for team in teams: self.assertIsInstance(team.address, str) self.assertIsInstance(team.aws_club_slug, str) self.assertIsInstance(team.city, str) self.assertIsInstance(team.club, str) self.assertIsInstance(team.club_common_name, str) self.assertIsInstance(team.club_common_url, str) self.assertIsInstance(team.club_full_name, str) self.assertIsInstance(team.club_id, int) self.assertIsInstance(team.club_spanish_name, str) self.assertIsInstance(team.country, str) self.assertIsInstance(team.dc_site, str) self.assertIsInstance(team.display_code, str) self.assertIsInstance(team.division, str) self.assertIsInstance(team.es_track_code, str) self.assertIsInstance(team.esp_common_name, str) self.assertIsInstance(team.esp_common_url, str) self.assertIsInstance(team.facebook, str) self.assertIsInstance(team.fanphotos_url, str) self.assertIsInstance(team.fb_app_id, int) self.assertIsInstance(team.field, str) self.assertIsInstance(team.google_tag_manager, str) try: self.assertIsInstance(team.googleplus_id, long) except NameError: self.assertIsInstance(team.googleplus_id, int) self.assertIsInstance(team.historical_team_code, str) self.assertIsInstance(team.id, int) self.assertIsInstance(team.instagram, str) self.assertIsInstance(team.instagram_id, int) self.assertIsInstance(team.league, str) self.assertIsInstance(team.location, str) self.assertIsInstance(team.medianet_id, int) self.assertIsInstance(team.mobile_es_url, str) self.assertIsInstance(team.mobile_short_code, (int, str)) self.assertIsInstance(team.mobile_url, str) self.assertIsInstance(team.mobile_url_base, str) self.assertIsInstance(team.name_display_long, str) self.assertIsInstance(team.name_display_short, str) self.assertIsInstance(team.newsletter_category_id, int) self.assertIsInstance(team.newsletter_group_id, int) self.assertIsInstance(team.phone, str) self.assertIsInstance(team.photostore_url, str) self.assertIsInstance(team.pinterest, str) self.assertIsInstance(team.pinterest_verification, str) self.assertIsInstance(team.pressbox_title, str) self.assertIsInstance(team.pressbox_url, str) self.assertIsInstance(team.primary, str) self.assertIsInstance(team.primary_link, str) self.assertIsInstance(team.postal_code, (int, str)) self.assertIsInstance(team.secondary, str) self.assertIsInstance(team.shop_entry_code, int) self.assertIsInstance(team.snapchat, str) self.assertIsInstance(team.state_province, str) self.assertIsInstance(team.team_code, str) self.assertIsInstance(team.team_id, int) self.assertIsInstance(team.tertiary, str) self.assertIsInstance(team.timezone, str) self.assertIsInstance(team.track_code, str) self.assertIsInstance(team.track_code_dev, str) self.assertIsInstance(team.track_filter, str) self.assertIsInstance(team.tumblr, str) self.assertIsInstance(team.twitter, str) self.assertIsInstance(team.twitter_es, str) self.assertIsInstance(team.url_cache, str) self.assertIsInstance(team.url_esp, str) self.assertIsInstance(team.url_prod, str) self.assertIsInstance(team.venue_id, int) self.assertIsInstance(team.vine, (int, str)) self.assertIsInstance(team.youtube, str) team = teams[17] self.assertEqual(team.address, '120-01 Roosevelt Avenue') self.assertEqual(team.aws_club_slug, 'mets') self.assertEqual(team.city, 'Corona') self.assertEqual(team.club, 'nym') self.assertEqual(team.club_common_name, 'Mets') self.assertEqual(team.club_common_url, 'mets.com') self.assertEqual(team.club_full_name, 'New York Mets') self.assertEqual(team.club_id, 20) self.assertEqual(team.club_spanish_name, 'Los Mets de Nueva York') self.assertEqual(team.country, 'USA') self.assertEqual(team.dc_site, 'mets.mlb') self.assertEqual(team.display_code, 'nym') self.assertEqual(team.division, 'East') self.assertEqual(team.es_track_code, 'mlbmetses') self.assertEqual(team.esp_common_name, 'Mets') self.assertEqual(team.esp_common_url, 'losmets.com') self.assertEqual(team.facebook, 'Mets') self.assertEqual(team.facebook_es, 284924024933471) self.assertEqual(team.fanphotos_url, '') self.assertEqual(team.fb_app_id, 94421890077) self.assertEqual(team.field, 'Citi Field') self.assertEqual(team.google_tag_manager, 'GTM-WGDHL4') self.assertEqual(team.googleplus_id, 111969268508366177113) self.assertEqual(team.historical_team_code, 'NYN') self.assertEqual(team.id, 36018) self.assertEqual(team.instagram, 'mets') self.assertEqual(team.instagram_id, 50927135) self.assertEqual(team.league, 'National') self.assertEqual(team.location, 'New York') self.assertEqual(team.medianet_id, 25) self.assertEqual(team.mobile_es_url, 'http://m.es.mets.mlb.com') self.assertEqual(team.mobile_short_code, 48593) self.assertEqual(team.mobile_url, 'http://m.mets.mlb.com') self.assertEqual(team.mobile_url_base, 'mets.mlb.com') self.assertEqual(team.name_display_long, 'The New York Mets') self.assertEqual(team.name_display_short, 'NY Mets') self.assertEqual(team.newsletter_category_id, 21) self.assertEqual(team.newsletter_group_id, 29) self.assertEqual(team.phone, '(718) 507-6387') self.assertEqual( team.photostore_url, 'https://photostore.mlb.com/collections/new-york-mets') self.assertEqual(team.pinterest, 'metsbaseball') self.assertEqual(team.pinterest_verification, 'a7f4172888a65c72793112432c061cc3') self.assertEqual(team.pressbox_title, 'MetsPressbox.com') self.assertEqual(team.pressbox_url, 'metspressbox.com') self.assertEqual(team.primary, '#003581') self.assertEqual(team.primary_link, '#ff5910') self.assertEqual(team.postal_code, 11368) self.assertEqual(team.secondary, '#ff5731') self.assertEqual(team.shop_entry_code, 1452359) self.assertEqual(team.snapchat, 'mets') self.assertEqual(team.state_province, 'NY') self.assertEqual(team.team_code, 'nyn') self.assertEqual(team.team_id, 121) self.assertEqual(team.tertiary, '#e6e6e6') self.assertEqual(team.timezone, 'ET') self.assertEqual(team.track_code, 'mlbmets') self.assertEqual(team.track_code_dev, 'devmlbnewyork') self.assertEqual(team.track_filter, 'newyork,mets') self.assertEqual(team.tumblr, 'mets') self.assertEqual(team.twitter, 'Mets') self.assertEqual(team.twitter_es, 'LosMets') self.assertEqual(team.url_cache, 'newyork.mets.mlb.com') self.assertEqual(team.url_esp, '/es/index.jsp?c_id=nym') self.assertEqual(team.url_prod, 'mets.mlb.com') self.assertEqual(team.venue_id, 3289) self.assertEqual(team.vine, 929089218578374656) self.assertEqual(team.youtube, 'UCgIMbGazP0uBDy9JVCqBUaA')
def get_team_id(team_name): teams = mlbgame.teams() for team in teams: if team_name in str(team): return team.team_id
async def on_message(message): # we do not want the bot to reply to itself if message.author == client.user: print(message.content) return if message.content.startswith('!hello'): msg = 'Hello {0.author.mention}'.format(message) channel = message.channel await channel.send(msg) elif message.content == 'thicc': msg = 'im a thicc boi' channel = message.channel await channel.send(msg) elif message.content.lower() == 'thicc boi help': option_message = ("Here are your options:\n" "- Thiccest team in the league\n" "- Thiccest player in the league\n" "- Cutest player in the league\n") channel = message.channel await channel.send(option_message) if message.content.lower() == "thiccest team in the league": channel = message.channel await channel.send( "Calculating each team's rating on the THICC-ter scale...") for team in mlbgame.teams(): team_average_bmi(str(team)) response = get_thiccest_team() await channel.send(response) elif message.content.lower() == "thiccest player in the league": channel = message.channel await channel.send("Calculating each bois thicc rating...") for team in mlbgame.teams(): thiccest_boi(str(team)) response = get_thiccest_man() await channel.send(response) # elif message.content.startswith("Thiccest player on"): # team_thiccest = {} # contents = message.content.split("on") # team_name = contents[1] # print(team_name) # teams = mlbgame.teams() # thiccest_boi(team_name) # for boy in team_thiccest: # await client.send_message(message.channel, boy) # elif message.content.lower() == "show average team bmis": # await client.send_message( # message.channel, "Calculating each team's rating on the THICC-ter scale...") # for team in mlbgame.teams(): # team_average_bmi(str(team)) # await client.send_message( # message.channel, "Average Team BMIs:") # for x in team_bmis: # await client.send_message( # message.channel, ("Team:", x, "BMI", team_bmis[x])) # elif message.content.lower() == "show thiccest players on all teams": # await client.send_message( # message.channel, "Calculating each bois thicc rating...") # for team in mlbgame.teams(): # thiccest_boi(str(team)) # await client.send_message( # message.channel, "Thiccest Bois in the LEAGUE:") # for x in team_thiccest: # await client.send_message( # message.channel, ("Team:", # x, # "Thiccest:", # team_thiccest[x][0], # "BMI:", # team_thiccest[x][1] # )) elif message.content.lower() == "cutest player in the league": channel = message.channel await channel.send( "The Cutest boi in the league is Willians Astudillo, aka La Tortuga" ) await channel.send( "http://stmedia.stimg.co/ctyp-torguga-chugging.jpg?w=800")
if each[1] == thiccest_man: print("The THICCEST man in the MLB is {} with a BMI of {}. " "Wow!".format(each[0], each[1])) return if __name__ == '__main__': while True: user_option = input("Choose an option:\n" "1. Thiccest team in the league\n" "2. Thiccest player in the league\n" "3. Show average team BMIs\n" "4. Show thiccest players on all teams\n" "5. Cutest player in the league\n") if user_option == "1": teams = mlbgame.teams() print("Calculating each team's rating on the THICC-ter scale...") for team in mlbgame.teams(): team_average_bmi(str(team)) get_thiccest_team() again = input("Would you like to choose another option? y/n: ") if again.lower() == "n": break elif user_option == "2": teams = mlbgame.teams() print("Calculating each bois thicc rating...") for team in mlbgame.teams(): thiccest_boi(str(team)) get_thiccest_man() again = input("Would you like to choose another option? y/n: ") if again.lower() == "n":