def pullTeamFieldingData(team='', year='2018'):
    url = 'https://www.baseball-reference.com/leagues/MLB/' + str(
        year) + '-standard-fielding.shtml'
    teamFieldingData = pullTable(url, 'teams_standard_fielding')

    teams = teamFieldingData['Tm']

    if (team != ''):
        for i in range(len(teams)):
            if (teams[i] == team):
                return teamFieldingData.iloc[i]

    return teamFieldingData
def pullPlayerBattingData(name, year='2018'):
    url = 'https://www.baseball-reference.com/leagues/MLB/' + str(
        year) + '-standard-batting.shtml'
    hittersData = pullTable(url, 'players_standard_batting')
    players = hittersData['Name']

    for i in range(len(players)):
        concisePlayer = ''.join(letter for letter in players[i]
                                if letter.isalnum())
        conciseName = ''.join(letter for letter in name if letter.isalnum())
        if (concisePlayer.lower() == conciseName.lower()):
            return (hittersData.iloc[i])

    return ('Batting data for ' + str(name) + ' in ' + str(year) +
            ' is not avaliable.')
def pullGameData(team, year='2018', date=''):
    team = team.upper()
    url = "http://www.baseball-reference.com/teams/" + str(team) + "/" + str(
        year) + "-schedule-scores.shtml"
    scoreTable = pullTable(url, 'team_schedule')
    gameDate = scoreTable['Date']
    teamSchedule = scoreTable

    if (date != ''):
        allDates = []
        for game in gameDate:
            daySlash = ''
            dateArray = (game.split(' '))
            month = dateArray[1]
            day = dateArray[2]

            mapping = {
                "Mar": "3",
                "Apr": "4",
                "May": "5",
                "Jun": "6",
                "Jul": "7",
                "Aug": "8",
                "Sep": "9",
                "Oct": "10",
                "Nov": "11"
            }
            monthNum = mapping[month]
            daySlash = (str(monthNum) + '/' + str(day))

            allDates.append(daySlash)

        for i in range(len(allDates)):
            if (allDates[i] == date):
                teamSchedule = (scoreTable.iloc[i])
                break
            else:
                teamSchedule = (str(team) + ' did not play on ' + str(date) +
                                '/' + str(year))

    return teamSchedule
def pullStandings(year=2018, division='expanded_standings_overall'):
    url = 'https://www.baseball-reference.com/leagues/MLB/' + str(
        year) + '-standings.shtml'
    league = 0

    if (division != 'expanded_standings_overall'):
        divisionArray = division.split(' ')
        if (divisionArray[0] == 'NL'):
            league = 1

        if (divisionArray[1] == 'E'):
            division = 'standings_E'
        elif (divisionArray[1] == 'C'):
            division = 'standings_C'
        elif (divisionArray[1] == 'W'):
            division = 'standings_W'
        else:
            print('That Division is not Avaliable')

    standingsTable = pullTable(url, division, league)
    return standingsTable