Example #1
0
 def test_int(self):
     self.assertEqual('1999-00', cleanse_season(99))
     self.assertEqual('1999-00', cleanse_season(1999))
     self.assertEqual('2000-01', cleanse_season(0))
     self.assertEqual('2000-01', cleanse_season(2000))
     self.assertEqual('1985-86', cleanse_season(85))
     self.assertEqual('1985-86', cleanse_season(1985))
     self.assertEqual('2009-10', cleanse_season(9))
     self.assertEqual('2009-10', cleanse_season(2009))
     self.assertEqual('2011-12', cleanse_season(11))
     self.assertEqual('2011-12', cleanse_season(2011))
Example #2
0
 def test_int(self):
     self.assertEqual('1999-00', cleanse_season(99))
     self.assertEqual('1999-00', cleanse_season(1999))
     self.assertEqual('2000-01', cleanse_season(0))
     self.assertEqual('2000-01', cleanse_season(2000))
     self.assertEqual('1985-86', cleanse_season(85))
     self.assertEqual('1985-86', cleanse_season(1985))
     self.assertEqual('2009-10', cleanse_season(9))
     self.assertEqual('2009-10', cleanse_season(2009))
     self.assertEqual('2011-12', cleanse_season(11))
     self.assertEqual('2011-12', cleanse_season(2011))
Example #3
0
def all_players(season, all_time=False):
    """
    return all players
    args:
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list)

    each player is a dict with the following available keys
    ["PERSON_ID","DISPLAY_LAST_COMMA_FIRST","ROSTERSTATUS","FROM_YEAR",
    "TO_YEAR","PLAYERCODE"]

    """

    # IsOnlyCurrentSeason: 0 is false 1 is true
    cur_season = 1
    if all_time:
        cur_season = 0

    endpoint = 'http://stats.nba.com/stats/commonallplayers'
    payload = {
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "IsOnlyCurrentSeason": cur_season
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonAllPlayers']
Example #4
0
def all_players(season, all_time=False):
    """
    return all players
    args:
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list)

    each player is a dict with the following available keys
    ["PERSON_ID","DISPLAY_LAST_COMMA_FIRST","ROSTERSTATUS","FROM_YEAR",
    "TO_YEAR","PLAYERCODE"]

    """

    # IsOnlyCurrentSeason: 0 is false 1 is true
    cur_season = 1
    if all_time:
        cur_season = 0

    endpoint = 'http://stats.nba.com/stats/commonallplayers'
    payload = {
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "IsOnlyCurrentSeason": cur_season
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonAllPlayers']
Example #5
0
def player_game_log(player_id, season):
    """
    return games that a player has already played in given season
    args:
        player_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        games (list): games a player has played in given season

    each game is a dict with the following available keys
    ["SEASON_ID","PLAYER_ID","GAME_ID","GAME_DATE","MATCHUP","WL","MIN",
    "FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM","FTA","FT_PCT",
    "OREB","DREB","REB","AST","STL","BLK","TOV","PF","PTS","PLUS_MINUS",
    "VIDEO_AVAILABLE"]

    """
    endpoint = 'http://stats.nba.com/stats/playergamelog'
    payload = {
        "PlayerID": player_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season"
    }
    response = utils.get_response(endpoint, payload)
    return response['PlayerGameLog']
Example #6
0
def team_game_log(team_id, season):
    """
    return games that a team has already played in given season
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        games (list): games a team has played in given season

    each game is a dict with the following available keys
    ["TEAM_ID","GAME_ID","GAME_DATE","MATCHUP","WL","MIN",
    "FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM",
    "FTA","FT_PCT","OREB","DREB","REB","AST","STL","BLK",
    "TOV","PF","PTS"]

    """
    endpoint = 'http://stats.nba.com/stats/teamgamelog'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season"
    }
    response = utils.get_response(endpoint, payload)
    return response['TeamGameLog']
Example #7
0
def player_game_log(player_id, season):
    """
    return games that a player has already played in given season
    args:
        player_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        games (list): games a player has played in given season

    each game is a dict with the following available keys
    ["SEASON_ID","PLAYER_ID","GAME_ID","GAME_DATE","MATCHUP","WL","MIN",
    "FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM","FTA","FT_PCT",
    "OREB","DREB","REB","AST","STL","BLK","TOV","PF","PTS","PLUS_MINUS",
    "VIDEO_AVAILABLE"]

    """
    endpoint = 'http://stats.nba.com/stats/playergamelog'
    payload = {
        "PlayerID": player_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season"
    }
    response = utils.get_response(endpoint, payload)
    return response['PlayerGameLog']
Example #8
0
def team_game_log(team_id, season):
    """
    return games that a team has already played in given season
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        games (list): games a team has played in given season

    each game is a dict with the following available keys
    ["TEAM_ID","GAME_ID","GAME_DATE","MATCHUP","WL","MIN",
    "FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM",
    "FTA","FT_PCT","OREB","DREB","REB","AST","STL","BLK",
    "TOV","PF","PTS"]

    """
    endpoint = 'http://stats.nba.com/stats/teamgamelog'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season"
    }
    response = utils.get_response(endpoint, payload)
    return response['TeamGameLog']
Example #9
0
def all_players_stats(season):
    # TODO all users to specify what type of stats
    """
    return basic stats for all players in a season
    args:
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list): players and their stats for the season

    each player is a dict with the following available keys
    ["PLAYER_ID","PLAYER_NAME","TEAM_ID","TEAM_ABBREVIATION","GP","W","L",
    "W_PCT","MIN","FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM","FTA",
    "FT_PCT","OREB","DREB","REB","AST","TOV","STL","BLK","BLKA","PF","PFD",
    "PTS","PLUS_MINUS","DD2","TD3","CFID","CFPARAMS"]

    """
    endpoint = 'http://stats.nba.com/stats/leaguedashplayerstats'
    payload = {
        "MeasureType":"Base",
        "PerMode":"PerGame",
        "PlusMinus":"N",
        "PaceAdjust":"N",
        "Rank":"N",
        "LeagueID":"00",
        "Season":utils.cleanse_season(season),
        "SeasonType":"Regular Season",
        "Outcome": None,
        "Location": None,
        "Month":0,
        "SeasonSegment": None,
        "DateFrom": None,
        "DateTo": None,
        "OpponentTeamID":0,
        "VsConference": None,
        "VsDivision": None,
        "GameSegment": None,
        "Period":0,
        "LastNGames":0,
        "GameScope": None,
        "PlayerExperience": None,
        "PlayerPosition": None,
        "StarterBench": None
    }
    response = utils.get_response(endpoint, payload)
    # TODO get corrent name
    return response['LeagueDashPlayerStats']
Example #10
0
def all_players_stats(season):
    # TODO all users to specify what type of stats
    """
    return basic stats for all players in a season
    args:
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list): players and their stats for the season

    each player is a dict with the following available keys
    ["PLAYER_ID","PLAYER_NAME","TEAM_ID","TEAM_ABBREVIATION","GP","W","L",
    "W_PCT","MIN","FGM","FGA","FG_PCT","FG3M","FG3A","FG3_PCT","FTM","FTA",
    "FT_PCT","OREB","DREB","REB","AST","TOV","STL","BLK","BLKA","PF","PFD",
    "PTS","PLUS_MINUS","DD2","TD3","CFID","CFPARAMS"]

    """
    endpoint = 'http://stats.nba.com/stats/leaguedashplayerstats'
    payload = {
        "MeasureType": "Base",
        "PerMode": "PerGame",
        "PlusMinus": "N",
        "PaceAdjust": "N",
        "Rank": "N",
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season",
        "Outcome": None,
        "Location": None,
        "Month": 0,
        "SeasonSegment": None,
        "DateFrom": None,
        "DateTo": None,
        "OpponentTeamID": 0,
        "VsConference": None,
        "VsDivision": None,
        "GameSegment": None,
        "Period": 0,
        "LastNGames": 0,
        "GameScope": None,
        "PlayerExperience": None,
        "PlayerPosition": None,
        "StarterBench": None
    }
    response = utils.get_response(endpoint, payload)
    # TODO get corrent name
    return response['LeagueDashPlayerStats']
Example #11
0
def team_coaching_staff(team_id, season):
    """
    return a given team's coaching staff
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        coaches (list): 

    each coach is a dict with the following available keys
    ["TEAM_ID","SEASON","COACH_ID","FIRST_NAME","LAST_NAME","COACH_NAME",
    "COACH_CODE","IS_ASSISTANT","COACH_TYPE","SCHOOL","SORT_SEQUENCE"]

    """
    endpoint = 'http://stats.nba.com/stats/commonteamroster'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season)
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonTeamRoster']
Example #12
0
def team_roster(team_id, season):
    """
    return players on a team (only current players if this season)
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list): players on roster

    each player is a dict with the following available keys
    ["TeamID","SEASON","LeagueID","PLAYER","NUM","POSITION","HEIGHT",
    "WEIGHT","BIRTH_DATE","AGE","EXP","SCHOOL","PLAYER_ID"]

    """
    endpoint = 'http://stats.nba.com/stats/commonteamroster'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season)
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonTeamRoster']
Example #13
0
def team_coaching_staff(team_id, season):
    """
    return a given team's coaching staff
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        coaches (list): 

    each coach is a dict with the following available keys
    ["TEAM_ID","SEASON","COACH_ID","FIRST_NAME","LAST_NAME","COACH_NAME",
    "COACH_CODE","IS_ASSISTANT","COACH_TYPE","SCHOOL","SORT_SEQUENCE"]

    """
    endpoint = 'http://stats.nba.com/stats/commonteamroster'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season)
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonTeamRoster']
Example #14
0
def team_roster(team_id, season):
    """
    return players on a team (only current players if this season)
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        players (list): players on roster

    each player is a dict with the following available keys
    ["TeamID","SEASON","LeagueID","PLAYER","NUM","POSITION","HEIGHT",
    "WEIGHT","BIRTH_DATE","AGE","EXP","SCHOOL","PLAYER_ID"]

    """
    endpoint = 'http://stats.nba.com/stats/commonteamroster'
    payload = {
        "TeamID": team_id,
        "LeagueID": "00",
        "Season": utils.cleanse_season(season)
    }
    response = utils.get_response(endpoint, payload)
    return response['CommonTeamRoster']
Example #15
0
def team_info(team_id, season):
    """
    return a team's information
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        info (dict)

    info is a dict with the following available keys
    ["TEAM_ID","SEASON_YEAR","TEAM_CITY","TEAM_NAME","TEAM_ABBREVIATION",
    "TEAM_CONFERENCE","TEAM_DIVISION","TEAM_CODE","W","L","PCT",
    "CONF_RANK","DIV_RANK","MIN_YEAR","MAX_YEAR"]

    """
    endpoint = 'http://stats.nba.com/stats/teaminfocommon'
    payload = {
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season",
        "TeamID": team_id
    }
    response = utils.get_response(endpoint, payload)
    return response['TeamInfoCommon']
Example #16
0
def team_info(team_id, season):
    """
    return a team's information
    args:
        team_id (int)
        season: format ex: '1999-00', also accepts 1999 or 99
    returns:
        info (dict)

    info is a dict with the following available keys
    ["TEAM_ID","SEASON_YEAR","TEAM_CITY","TEAM_NAME","TEAM_ABBREVIATION",
    "TEAM_CONFERENCE","TEAM_DIVISION","TEAM_CODE","W","L","PCT",
    "CONF_RANK","DIV_RANK","MIN_YEAR","MAX_YEAR"]

    """
    endpoint = 'http://stats.nba.com/stats/teaminfocommon'
    payload = {
        "LeagueID": "00",
        "Season": utils.cleanse_season(season),
        "SeasonType": "Regular Season",
        "TeamID": team_id
    }
    response = utils.get_response(endpoint, payload)
    return response['TeamInfoCommon']
Example #17
0
 def test_str(self):
     self.assertEqual('2000-01', cleanse_season('2000-2001'))
     self.assertEqual('2014-15', cleanse_season('2014-15'))
     self.assertEqual('2014-15', cleanse_season('2014'))
     self.assertEqual('2014-15', cleanse_season('14'))
     self.assertEqual('2000-01', cleanse_season('0'))
Example #18
0
 def test_str(self):
     self.assertEqual('2000-01', cleanse_season('2000-2001'))
     self.assertEqual('2014-15', cleanse_season('2014-15'))
     self.assertEqual('2014-15', cleanse_season('2014'))
     self.assertEqual('2014-15', cleanse_season('14'))
     self.assertEqual('2000-01', cleanse_season('0'))