def create_player(player_xml): if (player_xml.get('num') and player_xml.get('num') != '--' and player_xml.get('num') != '-' and player_xml.get('num') != ' ' and player_xml.get('num') != '?' and player_xml.get('num') != 'null'): player_num = int(player_xml.get('num')) else: player_num = None new_player = Player(player_xml.get('last'), player_xml.get('first'), int(player_xml.get('id')), None, None, player_num) new_player.bat_side = player_xml.get('bats') new_player.pitch_hand = player_xml.get('rl') return new_player
def set_player_list(team_dict, gamedata_dict, team): digit_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] for player_id, this_player_dict in team_dict['players'].items(): gamedata_player_dict = gamedata_dict['players'][player_id] jersey_number = '' if ('jerseyNumber' in this_player_dict and this_player_dict.get('jerseyNumber')): if all([ character in digit_list for character in this_player_dict.get('jerseyNumber') ]): jersey_number = int(this_player_dict.get('jerseyNumber')) (first_name, last_name) = parse_name(this_player_dict['person']['fullName']) new_player = Player( last_name, first_name, this_player_dict['person']['id'], float(this_player_dict['seasonStats']['batting']['obp']), float(this_player_dict['seasonStats']['batting']['slg']), jersey_number) new_player.pitch_hand = gamedata_player_dict['pitchHand']['code'] new_player.bat_side = gamedata_player_dict['batSide']['code'] if this_player_dict['seasonStats']['pitching']['era'] != '-.--': this_era = float( this_player_dict['seasonStats']['pitching']['era']) if this_era != 0.0: new_player.era = this_era else: new_player.era = '' else: new_player.era = '' team.append(new_player)