def get_pitching_line(team_name): game_stats = mlb_data.get_player_stats(team_name) if is_team_at_home(team_name): pitcher_stats = game_stats['home_pitching'][0] else: pitcher_stats = game_stats['away_pitching'][0] pitcher_outs = int(pitcher_stats['out']) pitcher_er = pitcher_stats['er'] pitcher_r = pitcher_stats['r'] pitcher_hits = pitcher_stats['h'] pitcher_so = pitcher_stats['so'] pitcher_walks = pitcher_stats['bb'] pitcher_np = pitcher_stats['np'] pitcher_strikes = pitcher_stats['s'] pitcher_wins = pitcher_stats['w'] pitcher_losses = pitcher_stats['l'] pitcher_era = pitcher_stats['era'] pitcher_id = pitcher_stats['id'] if pitcher_outs % 3 == 1: innings_pitched = str(int((pitcher_outs - 1) / 3)) IP = innings_pitched + ".1" elif pitcher_outs % 3 == 2: innings_pitched = str(int((pitcher_outs - 2) / 3)) IP = innings_pitched + ".2" else: IP = str(pitcher_outs / 3) + "" message = "http://gdx.mlb.com/images/gameday/mugshots/mlb/" + pitcher_id + "@4x.jpg " + pitcher_stats[ 'name'] + " pitching line: " + IP + "IP " + pitcher_er + "ER " + pitcher_hits + "H " + pitcher_so + "SO " + pitcher_walks + "BB " + pitcher_strikes + "-" + pitcher_np + " strikes/pitches " return message
def get_player_id(team_name, player_uniform_name): stats = mlb_data.get_player_stats(team_name) if is_team_at_home(team_name): for stat in stats['home_batting']: name = stat['name'].split(",", 1)[0] if player_uniform_name == name.lower(): return stat['id'] for stat in stats['home_pitching']: name = stat['name'].split(",", 1)[0] if player_uniform_name == name.lower(): return stat['id'] else: for stat in stats['away_batting']: name = stat['name'].split(",", 1)[0] if player_uniform_name == name.lower(): return stat['id'] for stat in stats['away_pitching']: name = stat['name'].split(",", 1)[0] if player_uniform_name == name.lower(): return stat['id']
def get_player_season_stats(team_name, player_name): game_stats = mlb_data.get_player_stats(team_name) if is_team_at_home(team_name): team_player_stats = game_stats['home_batting'] else: team_player_stats = game_stats['away_batting'] for player in team_player_stats: if player['name'].lower() == player_name: player_id = player['id'] player_name = player['name_display_first_last'] player_avg = player['avg'] player_obp = player['obp'] player_slg = player['slg'] player_ops = player['ops'] message = ' http://gdx.mlb.com/images/gameday/mugshots/mlb/' + player_id + '.jpg ' + player_name + " " + player_avg + " AVG | " + player_obp + " OBP | " + player_slg + " SLG | " + player_ops + " OPS" return message return "Sorry, i don't recognize that name, please use the name on the player uniform, or make sure he plays for the " + team_name
def get_player_stats(team_name, player_name): game_stats = mlb_data.get_player_stats(team_name) if is_team_at_home(team_name): team_player_stats = game_stats['home_batting'] else: team_player_stats = game_stats['away_batting'] for player in team_player_stats: if player['name'].lower() == player_name: player_at_bats = player['ab'] player_hits = player['h'] player_walks = player['bb'] player_home_runs = player['hr'] player_rbi = player['rbi'] player_lob = player['lob'] message = player[ 'name'] + " is " + player_hits + "-" + player_at_bats + " today " if int(player_walks) == 1: message += "with a walk " elif int(player_walks) > 1: message += "with " + player_walks + " walks " if int(player_home_runs) == 1: message += "He's also hit a home run " elif int(player_home_runs) > 1: message += "He's also hit " + player_home_runs + " homers " if int(player_rbi) == 1: message += "and has one RBI " elif int(player_rbi) > 1: message += "and has " + player_rbi + " RBI's " if int(player_lob) >= 3: message += "also he stranded " + player_lob + " players on base" return message return "Sorry, i don't recognize that name, please use the name on the player uniform, or make sure he's in today's lineup for the " + team_name