diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..e8a5bf7 --- /dev/null +++ b/constants.py @@ -0,0 +1,781 @@ +CURRENT_SEASON = '2017-18' + +TEAMS = { + 'ATL': { + 'abbr': 'ATL', + 'city': 'Atlanta', + 'code': 'hawks', + 'conference': 'Eastern', + 'displayAbbr': 'ATL', + 'displayConference': 'Eastern', + 'division': 'Southeast', + 'id': '1610612737', + 'name': 'Hawks', + 'color': 'E2373E', + 'colors': ['E2373E', '002A5C', 'BAC4CA'] + }, 'BOS': { + 'abbr': 'BOS', + 'city': 'Boston', + 'code': 'celtics', + 'conference': 'Eastern', + 'displayAbbr': 'BOS', + 'displayConference': 'Eastern', + 'division': 'Atlantic', + 'id': '1610612738', + 'name': 'Celtics', + 'color': '007239', + 'colors': ['007239', 'AE8445', '982527', '000000'] + }, 'BKN': { + 'abbr': 'BKN', + 'city': 'Brooklyn', + 'code': 'nets', + 'conference': 'Eastern', + 'displayAbbr': 'BKN', + 'displayConference': 'Eastern', + 'division': 'Atlantic', + 'id': '1610612751', + 'name': 'Nets', + 'color': '000000', + 'colors': ['000000', 'FFFFFF'] + }, 'CHA': { + 'abbr': 'CHA', + 'city': 'Charlotte', + 'code': 'hornets', + 'conference': 'Eastern', + 'displayAbbr': 'CHA', + 'displayConference': 'Eastern', + 'division': 'Southeast', + 'id': '1610612766', + 'name': 'Hornets', + 'color': '00848E', + 'colors': ['00848E', '260F54', 'CCCCCC'] + }, 'CHI': { + 'abbr': 'CHI', + 'city': 'Chicago', + 'code': 'bulls', + 'conference': 'Eastern', + 'displayAbbr': 'CHI', + 'displayConference': 'Eastern', + 'division': 'Central', + 'id': '1610612741', + 'name': 'Bulls', + 'color': 'C60033', + 'colors': ['C60033', '000000'] + }, 'CLE': { + 'abbr': 'CLE', + 'city': 'Cleveland', + 'code': 'cavaliers', + 'conference': 'Eastern', + 'displayAbbr': 'CLE', + 'displayConference': 'Eastern', + 'division': 'Central', + 'id': '1610612739', + 'name': 'Cavaliers', + 'color': '860038', + 'colors': ['860038', '002D62', 'FDBA31'] + }, 'DAL': { + 'abbr': 'DAL', + 'city': 'Dallas', + 'code': 'mavericks', + 'conference': 'Western', + 'displayAbbr': 'DAL', + 'displayConference': 'Western', + 'division': 'Southwest', + 'id': '1610612742', + 'name': 'Mavericks', + 'color': '0063AF', + 'colors': ['0063AF', 'BAC4CA', '000000'] + }, 'DEN': { + 'abbr': 'DEN', + 'city': 'Denver', + 'code': 'nuggets', + 'conference': 'Western', + 'displayAbbr': 'DEN', + 'displayConference': 'Western', + 'division': 'Northwest', + 'id': '1610612743', + 'name': 'Nuggets', + 'color': '559FD6', + 'colors': ['559FD6', '006BB7', 'FEA927'] + }, 'DET': { + 'abbr': 'DET', + 'city': 'Detroit', + 'code': 'pistons', + 'conference': 'Eastern', + 'displayAbbr': 'DET', + 'displayConference': 'Eastern', + 'division': 'Central', + 'id': '1610612765', + 'name': 'Pistons', + 'color': 'EC003D', + 'colors': ['EC003D', '0058A6', '001D4A'] + }, 'GSW': { + 'abbr': 'GSW', + 'city': 'Golden State', + 'code': 'warriors', + 'conference': 'Western', + 'displayAbbr': 'GSW', + 'displayConference': 'Western', + 'division': 'Pacific', + 'id': '1610612744', + 'name': 'Warriors', + 'color': '0068B3', + 'colors': ['0068B3', 'FFC423'] + }, 'HOU': { + 'abbr': 'HOU', + 'city': 'Houston', + 'code': 'rockets', + 'conference': 'Western', + 'displayAbbr': 'HOU', + 'displayConference': 'Western', + 'division': 'Southwest', + 'id': '1610612745', + 'name': 'Rockets', + 'color': 'C60033', + 'colors': ['C60033', '000000'] + }, 'IND': { + 'abbr': 'IND', + 'city': 'Indiana', + 'code': 'pacers', + 'conference': 'Eastern', + 'displayAbbr': 'IND', + 'displayConference': 'Eastern', + 'division': 'Central', + 'id': '1610612754', + 'name': 'Pacers', + 'color': '001D4A', + 'colors': ['001D4A', 'FEAC2D', 'B0B2B5'] + }, 'LAC': { + 'abbr': 'LAC', + 'city': 'Los Angeles', + 'code': 'clippers', + 'conference': 'Western', + 'displayAbbr': 'LAC', + 'displayConference': 'Western', + 'division': 'Pacific', + 'id': '1610612746', + 'name': 'Clippers', + 'color': '00559A', + 'colors': ['00559A', 'EC003D'] + }, 'LAL': { + 'abbr': 'LAL', + 'city': 'Los Angeles', + 'code': 'lakers', + 'conference': 'Western', + 'displayAbbr': 'LAL', + 'displayConference': 'Western', + 'division': 'Pacific', + 'id': '1610612747', + 'name': 'Lakers', + 'color': 'FEA927', + 'colors': ['FEA927', '42186E', '000000'] + }, 'MEM': { + 'abbr': 'MEM', + 'city': 'Memphis', + 'code': 'grizzlies', + 'conference': 'Western', + 'displayAbbr': 'MEM', + 'displayConference': 'Western', + 'division': 'Southwest', + 'id': '1610612763', + 'name': 'Grizzlies', + 'color': '182A48', + 'colors': ['182A48', '4C78AD', 'FEA927', 'AAC8E5'] + }, 'MIA': { + 'abbr': 'MIA', + 'city': 'Miami', + 'code': 'heat', + 'conference': 'Eastern', + 'displayAbbr': 'MIA', + 'displayConference': 'Eastern', + 'division': 'Southeast', + 'id': '1610612748', + 'name': 'Heat', + 'color': '98002E', + 'colors': ['98002E', 'F88D1D', '000000'] + }, 'MIL': { + 'abbr': 'MIL', + 'city': 'Milwaukee', + 'code': 'bucks', + 'conference': 'Eastern', + 'displayAbbr': 'MIL', + 'displayConference': 'Eastern', + 'division': 'Central', + 'id': '1610612749', + 'name': 'Bucks', + 'color': 'C41230', + 'colors': ['C41230', '003815', 'BAC4CA'] + }, 'MIN': { + 'abbr': 'MIN', + 'city': 'Minnesota', + 'code': 'timberwolves', + 'conference': 'Western', + 'displayAbbr': 'MIN', + 'displayConference': 'Western', + 'division': 'Northwest', + 'id': '1610612750', + 'name': 'Timberwolves', + 'color': '#003F70', + 'colors': ['003F70', '006F42', 'BAC4CA', 'FFE211', 'DE2032', '000000'] + }, 'NOP': { + 'abbr': 'NOP', + 'city': 'New Orleans', + 'code': 'pelicans', + 'conference': 'Western', + 'displayAbbr': 'NOP', + 'displayConference': 'Western', + 'division': 'Southwest', + 'id': '1610612740', + 'name': 'Pelicans', + 'color': '#002B5C', + 'colors': ['002B5C', 'B4975A', 'E13A3E'] + }, 'NYK': { + 'abbr': 'NYK', + 'city': 'New York', + 'code': 'knicks', + 'conference': 'Eastern', + 'displayAbbr': 'NYK', + 'displayConference': 'Eastern', + 'division': 'Atlantic', + 'id': '1610612752', + 'name': 'Knicks', + 'color': 'F3571F', + 'colors': ['F3571F', '0067B2', 'BAC4CA'] + }, 'OKC': { + 'abbr': 'OKC', + 'city': 'Oklahoma City', + 'code': 'thunder', + 'conference': 'Western', + 'displayAbbr': 'OKC', + 'displayConference': 'Western', + 'division': 'Northwest', + 'id': '1610612760', + 'name': 'Thunder', + 'color': 'FDBB30', + 'colors': ['FDBB30', 'F05133', '007DC3', '002D62'] + }, 'ORL': { + 'abbr': 'ORL', + 'city': 'Orlando', + 'code': 'magic', + 'conference': 'Eastern', + 'displayAbbr': 'ORL', + 'displayConference': 'Eastern', + 'division': 'Southeast', + 'id': '1610612753', + 'name': 'Magic', + 'color': '006BB7', + 'colors': ['006BB7', 'BAC4CA', '000000'] + }, 'PHI': { + 'abbr': 'PHI', + 'city': 'Philadelphia', + 'code': 'sixers', + 'conference': 'Eastern', + 'displayAbbr': 'PHI', + 'displayConference': 'Eastern', + 'division': 'Atlantic', + 'id': '1610612755', + 'name': 'Sixers', + 'color': 'EC003D', + 'colors': ['EC003D', '00559A', 'BAC4CA'] + }, 'PHX': { + 'abbr': 'PHX', + 'city': 'Phoenix', + 'code': 'suns', + 'conference': 'Western', + 'displayAbbr': 'PHX', + 'displayConference': 'Western', + 'division': 'Pacific', + 'id': '1610612756', + 'name': 'Suns', + 'color': 'E45F1F', + 'colors': ['E45F1F', 'F89F1B', 'BAC4CA', '000000'] + }, 'POR': { + 'abbr': 'POR', + 'city': 'Portland', + 'code': 'blazers', + 'conference': 'Western', + 'displayAbbr': 'POR', + 'displayConference': 'Western', + 'division': 'Northwest', + 'id': '1610612757', + 'name': 'Trail Blazers', + 'color': 'DE2032', + 'colors': ['DE2032', 'BAC4CA', '000000'] + }, 'SAC': { + 'abbr': 'SAC', + 'city': 'Sacramento', + 'code': 'kings', + 'conference': 'Western', + 'displayAbbr': 'SAC', + 'displayConference': 'Western', + 'division': 'Pacific', + 'id': '1610612758', + 'name': 'Kings', + 'color': '542E91', + 'colors': ['542E91', 'BAC4CA', '000000'] + }, 'SAS': { + 'abbr': 'SAS', + 'city': 'San Antonio', + 'code': 'spurs', + 'conference': 'Western', + 'displayAbbr': 'SAS', + 'displayConference': 'Western', + 'division': 'Southwest', + 'id': '1610612759', + 'name': 'Spurs', + 'color': '#BA24CA', + 'colors': ['BA24CA', '000000'] + }, 'TOR': { + 'abbr': 'TOR', + 'city': 'Toronto', + 'code': 'raptors', + 'conference': 'Eastern', + 'displayAbbr': 'TOR', + 'displayConference': 'Eastern', + 'division': 'Atlantic', + 'id': '1610612761', + 'name': 'Raptors', + 'color': 'C60033', + 'colors': ['C60033', 'BAC4CA'] + }, 'UTA': { + 'abbr': 'UTA', + 'city': 'Utah', + 'code': 'jazz', + 'conference': 'Western', + 'displayAbbr': 'UTA', + 'displayConference': 'Western', + 'division': 'Northwest', + 'id': '1610612762', + 'name': 'Jazz', + 'color': '#002A5C', + 'colors': ['002A5C', '004812', 'FCB034', 'BACA4CA'] + }, 'WAS': { + 'abbr': 'WAS', + 'city': 'Washington', + 'code': 'wizards', + 'conference': 'Eastern', + 'displayAbbr': 'WAS', + 'displayConference': 'Eastern', + 'division': 'Southeast', + 'id': '1610612764', + 'name': 'Wizards', + 'color': '002A5B', + 'colors': ['002A5B', 'E21836', 'BAC4CA'] + } +} + + +class _DefaultN: + Default = 'N' + + +class _DefaultBlank: + Default = '' + + +class _DefaultZero: + Default = '0' + + +class League: + NBA = '00' + Default = NBA + + +class PerMode: + Totals = 'Totals' + PerGame = 'PerGame' + MinutesPer = 'MinutesPer' + Per48 = 'Per48' + Per40 = 'Per40' + Per36 = 'Per36' + PerMinute = 'PerMinute' + PerPossession = 'PerPossession' + PerPlay = 'PerPlay' + Per100Possessions = 'Per100Possessions' + Per100Plays = 'Per100Plays' + Default = PerGame + + +class SeasonType: + Regular = 'Regular Season' + Playoffs = 'Playoffs' + Default = Regular + + +class MeasureType: + Base = 'Base' + Advanced = 'Advanced' + Misc = 'Misc' + FourFactors = 'Four Factors' + Scoring = 'Scoring' + Opponent = 'Opponent' + Usage = 'Usage' + Default = Base + +class PtMeasureType: + SpeedDistance = 'SpeedDistance' + Drives = 'Drives' + Defense = 'Defense' + CatchShoot = 'CatchShoot' + Passing = 'Passing' + Possessions = 'Possessions' + PullUpShot = 'PullUpShot' + Rebounding = 'Rebounding' + Efficiency = 'Efficiency' + ElbowTouch = 'ElbowTouch' + PostTouch = 'PostTouch' + PaintTouch = 'PaintTouch' + +class GroupQuantity: + Default = 5 + + +class Outcome(_DefaultBlank): + Win = 'W' + Loss = 'L' + + +class Location(_DefaultBlank): + Home = 'Home' + Away = 'Away' + + +class SeasonSegment(_DefaultBlank): + EntireSeason = '' + PreAllStar = 'Pre All-Star' + PostAllStar = 'Post All-Star' + + +class DateFrom(_DefaultBlank): + pass + + +class DateTo(_DefaultBlank): + pass + + +class VsConference(_DefaultBlank): + All = '' + East = 'East' + West = 'West' + + +class VsDivision(_DefaultBlank): + All = '' + Atlantic = 'Atlantic' + Central = 'Central' + Northwest = 'Northwest' + Pacific = 'Pacific' + Southeast = 'Southeast' + Southwest = 'Southwest' + + +class GameSegment(_DefaultBlank): + EntireGame = '' + FirstHalf = 'First Half' + SecondHalf = 'Second Half' + Overtime = 'Overtime' + + +class ClutchTime(_DefaultBlank): + Last5Min = 'Last 5 Minutes' + Last4Min = 'Last 4 Minutes' + Last3Min = 'Last 3 Minutes' + Last2Min = 'Last 2 Minutes' + Last1Min = 'Last 1 Minutes' + Last30Sec = 'Last 30 Seconds' + Last10Sec = 'Last 10 Seconds' + + +class ShotClockRange(_DefaultBlank): + AllRanges = '' + # I honestly don't know anytime the shot clock would be off + ShotClockOff = 'ShotClock Off' + + def get(self, n): + if n > 24 or n < 0: + return '' + elif 22 <= n <= 24: + return '24-22' + elif 18 <= n < 22: + return '22-18 Very Early' + elif 15 <= n < 18: + return '18-15 Early' + elif 7 <= n < 15: + return '15-7 Average' + elif 4 <= n < 7: + return '7-4 Late' + elif 0 <= n < 4: + return '4-0 Very Late' + + +class AheadBehind(_DefaultBlank): + AheadOrBehind = 'Ahead or Behind' + AheadOrTied = 'Ahead or Tied' + BehindOrTied = 'Behind or Tied' + + +class PlusMinus(_DefaultN): + pass + + +class PaceAdjust(_DefaultN): + pass + + +class Rank(_DefaultN): + pass + + +class OpponentTeamID(_DefaultZero): + pass + + +class Period(_DefaultZero): + AllQuarters = '0' + FirstQuarter = '1' + SecondQuarter = '2' + ThirdQuarter = '3' + FourthQuarter = '4' + + def Overtime(self, n): + return str(4 + n) + + +class LastNGames(_DefaultZero): + pass + + +class PlayoffRound(_DefaultZero): + All = '0' + QuarterFinals = '1' + SemiFinals = '2' + ConferenceFinals = '3' + Finals = '4' + + +class Month(_DefaultZero): + All = '0' + October = '1' + November = '2' + December = '3' + January = '4' + February = '5' + March = '6' + April = '7' + May = '8' + June = '9' + July = '10' + August = '11' + September = '12' + + +class RangeType(_DefaultZero): + pass + + +class StartRange(_DefaultZero): + pass + + +class EndRange(_DefaultZero): + pass + + +class StartPeriod(Period): + pass + + +class EndPeriod(Period): + pass + + +class StatCategory: + PTS = 'PTS' + FGM = 'FGM' + FGA = 'FGA' + FG_PCT = 'FG%' + FG3M = '3PM' + FG3A = '3PA' + FG3_PCT = '3P%' + FTM = 'FTM' + FTA = 'FTA' + FT_PCT = 'FT%' + OREB = 'OREB' + DREB = 'DREB' + REB = 'REB' + AST = 'AST' + STL = 'STL' + BLK = 'BLK' + TOV = 'TOV' + EFF = 'EFF' + AST_TOV = 'AST/TO' + STL_TOV = 'STL/TOV' + PF = 'PF' + Default = PTS + + +class ContextMeasure: + # Not sure if this is mapped correctly. Source: https://github.com/bradleyfay/NBAStats + FGM = 'FGM' + FGA = 'FGA' + FG_PCT = 'FG_PCT' + FG3M = 'FG3m' + FG3A = 'FG3A' + FG3_PCT = 'FG3_PCT' + PF = 'PF' + EFG_PCT = 'EFG_PCT' + TS_PCT = 'TS_PCT' + PTS_FB = 'PTS_FB' + PTS_OFF_TOV = 'PTS_OFF_TOV' + PTS_2ND_CHANCE = 'PTS_2ND_CHANCE' + Default = FGM + + +class Scope: + AllPlayers = 'S' + Rookies = 'Rookies' + Default = AllPlayers + + +class PlayerScope: + # ugh this is so similar to Scope, why does it have its own + AllPlayers = 'All Players' + Rookies = 'Rookie' + Default = AllPlayers + + +class PlayerOrTeam: + Player = 'Player' + Team = 'Team' + Default = Player + + +class GameScope: + Season = 'Season' + Last10 = 'Last 10' + Yesterday = 'Yesterday' + Finals = 'Finals' + Default = Season + + +class Game_Scope(_DefaultBlank): + Last10 = 'Last 10' + Yesterday = 'Yesterday' + + +class Player_or_Team: + Player = 'P' + Team = 'T' + Default = Player + + +class Conference(VsConference): + pass + + +class Division(VsDivision): + pass + + +class TeamID(_DefaultZero): + pass + + +class GameID(_DefaultBlank): + pass + + +class RookieYear(_DefaultBlank): + pass + + +class PlayerExperience(_DefaultBlank): + Rookie = 'Rookie' + Sophomore = 'Sophomore' + Veteran = 'Veteran' + + +class PlayerPosition(_DefaultBlank): + Forward = 'F' + Center = 'C' + Guard = 'G' + + +class StarterBench(_DefaultBlank): + Starters = 'Starters' + Bench = 'Bench' + + +class DraftYear(_DefaultBlank): + pass + + +class DraftPick(_DefaultBlank): + FirstRound = '1st+Round' + SecondRound = '2nd+Round' + FirstPick = '1st+Pick' + Lottery = 'Lottery+Pick' + Top5 = 'Top+5+Pick' + Top10 = 'Top+10+Pick' + Top15 = 'Top+15+Pick' + Top20 = 'Top+20+Pick' + Top25 = 'Top+25+Pick' + Picks11Thru20 = 'Picks+11+Thru+20' + Picks21Thru30 = 'Picks+21+Thru+30' + Undrafted = 'Undrafted' + + +class College(_DefaultBlank): + pass + + +class Country(_DefaultBlank): + pass + + +class Height(_DefaultBlank): + ''' + Example: + for greater than 6ft8 api call should be GT+6-8 + for lower than 7ft3 api call should be LT+7-3 + ''' + + +class Weight(_DefaultBlank): + ''' + Example: + for greater than 225lbs api call should be GT+225lbs + ''' + + +class Counter: + Default = '1000' + + +class Sorter: + PTS = 'PTS' + FGM = 'FGM' + FGA = 'FGA' + FG_PCT = 'FG_PCT' + FG3M = 'FG3M' + FG3A = 'FG3A' + FG3_PCT = 'FG3_PCT' + FTM = 'FTM' + FTA = 'FTA' + FT_PCT = 'FT_PCT' + OREB = 'OREB' + DREB = 'DREB' + AST = 'AST' + STL = 'STL' + BLK = 'BLK' + TOV = 'TOV' + REB = 'REB' + Default = PTS + + +class Direction: + DESC = 'DESC' + ASC = 'ASC' + Default = DESC diff --git a/league.py b/league.py new file mode 100644 index 0000000..6e51ddc --- /dev/null +++ b/league.py @@ -0,0 +1,476 @@ +from nba_py import _api_scrape, _get_json +from nba_py.constants import * + + +class Leaders: + _endpoint = 'leagueleaders' + + def __init__(self, + league_id=League.Default, + per_mode=PerMode.Default, + stat_category=StatCategory.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + scope=Scope.Default,): + self.json = _get_json(endpoint=self._endpoint, + params={'LeagueID': league_id, + 'PerMode': per_mode, + 'StatCategory': stat_category, + 'Season': season, + 'SeasonType': season_type, + 'Scope': scope}) + + def results(self): + return _api_scrape(self.json, 0) + + +class LeadersTiles: + _endpoint = 'leaderstiles' + + def __init__(self, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + game_scope=GameScope.Default, + player_scope=PlayerScope.Default, + player_or_team=PlayerOrTeam.Default, + stat_category=StatCategory.Default): + self.json = _get_json(endpoint=self._endpoint, + params={'LeagueID': league_id, + 'Stat': stat_category, + 'Season': season, + 'SeasonType': season_type, + 'GameScope': game_scope, + 'PlayerScope': player_scope, + 'PlayerOrTeam': player_or_team}) + + def current_season_high(self): + return _api_scrape(self.json, 0) + + def alltime_season_high(self): + return _api_scrape(self.json, 1) + + def last_season_high(self): + return _api_scrape(self.json, 2) + + def low_season_high(self): + return _api_scrape(self.json, 3) + + +class Lineups: + _endpoint = 'leaguedashlineups' + + def __init__(self, + group_quantity=GroupQuantity.Default, + season_type=SeasonType.Default, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + last_n_games=LastNGames.Default): + self.json = _get_json(endpoint=self._endpoint, + params={'GroupQuantity': group_quantity, + 'SeasonType': season_type, + 'MeasureType': measure_type, + 'PerMode': per_mode, + 'PlusMinus': plus_minus, + 'PaceAdjust': pace_adjust, + 'Rank': rank, + 'Season': season, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'GameSegment': game_segment, + 'Period': period, + 'LastNGames': last_n_games}) + + def overall(self): + return _api_scrape(self.json, 0) + +class TeamStats: + _endpoint = 'leaguedashteamstats' + + def __init__(self, + conference=Conference.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + division=Division.Default, + game_scope=Game_Scope.Default, + game_segment=GameSegment.Default, + last_n_games=LastNGames.Default, + league_id=League.Default, + location=Location.Default, + measure_type=MeasureType.Default, + month=Month.Default, + opponent_team_id=OpponentTeamID.Default, + outcome=Outcome.Default, + playoff_round=PlayoffRound.Default, + pace_adjust=PaceAdjust.Default, + per_mode=PerMode.Default, + period=Period.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + plus_minus=PlusMinus.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + season_segment=SeasonSegment.Default, + season_type=SeasonType.Default, + shot_clock_range=ShotClockRange.Default, + starter_bench=StarterBench.Default, + team_id=TeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default + ): + self.json = _get_json(endpoint=self._endpoint, + params={'LeagueID': league_id, + 'SeasonType': season_type, + 'MeasureType': measure_type, + 'PerMode': per_mode, + 'PlusMinus': plus_minus, + 'PaceAdjust': pace_adjust, + 'Rank': rank, + 'Season': season, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'GameSegment': game_segment, + 'Period': period, + 'ShotClockRange': shot_clock_range, + 'LastNGames': last_n_games, + 'GameScope': game_scope, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'StarterBench': starter_bench, + }) + + def overall(self): + return _api_scrape(self.json, 0) + + +class PlayerStats: + _endpoint = 'leaguedashplayerstats' + + def __init__(self, + season_type=SeasonType.Default, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + playoff_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + team_id=TeamID.Default, + conference=Conference.Default, + division=Division.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default, + game_scope=Game_Scope.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + starter_bench=StarterBench.Default, + draft_year=DraftYear.Default, + draft_pick=DraftPick.Default, + college=College.Default, + country=Country.Default, + height=Height.Default, + weight=Weight.Default + ): + self.json = _get_json(endpoint=self._endpoint, + params={'SeasonType': season_type, + 'MeasureType': measure_type, + 'PerMode': per_mode, + 'PlusMinus': plus_minus, + 'PaceAdjust': pace_adjust, + 'Rank': rank, + 'Season': season, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'GameSegment': game_segment, + 'Period': period, + 'ShotClockRange': shot_clock_range, + 'LastNGames': last_n_games, + 'GameScope': game_scope, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'StarterBench': starter_bench, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight + }) + + def overall(self): + return _api_scrape(self.json, 0) + + +class _PlayerTrackingStats: + """ + Args: + :league_id: ID for the league to look in (Default is 00) + :season_type: Season type to consider (Regular or Playoffs) + :player_or_team: Filter by (Player or Team) + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :season: Season given to look up + :playoff_round: Playoff round + :outcome: Filter out by wins or losses + :location: Filter out by home or away + :month: Specify month to filter by + :season_segment: Filter by pre/post all star break + :date_from: Filter out games before a specific date + :date_to: Filter out games after a specific date + :opponent_team_id: Opponent team ID to look up + :vs_conference: Filter by conference + :vs_division: Filter by division + :team_id: ID of the team to look up + :conference: Filter by conference + :division: Filter by division + :last_n_games: Filter by number of games specified in N + :game_scope: Filter by GameScope (Yesterday, Last 10) + :player_experience: Player experience (Rookie, Sophomore, Veteran) + :player_position: Filter by position (Forward, Center, Guard) + :starter_bench: Filter by Starters or Bench + :draft_year: Filter by draft year + :draft_pick: Filter by draft pick (1st+Round, Lottery+Pick, etc.) + :college: Filter by college + :country: Filter by country + :height: Filter by player's height + :weight: Filter by player's weight + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'leaguedashptstats' + _pt_measure_type = '' + + def __init__(self, + league_id=League.Default, + season_type=SeasonType.Default, + player_or_team=PlayerOrTeam.Default, + per_mode=PerMode.Default, + season=CURRENT_SEASON, + playoff_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + team_id=TeamID.Default, + conference=Conference.Default, + division=Division.Default, + last_n_games=LastNGames.Default, + game_scope=Game_Scope.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + starter_bench=StarterBench.Default, + draft_year=DraftYear.Default, + draft_pick=DraftPick.Default, + college=College.Default, + country=Country.Default, + height=Height.Default, + weight=Weight.Default + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'LeagueID': league_id, + 'PtMeasureType': self._pt_measure_type, + 'SeasonType': season_type, + 'PlayerOrTeam': player_or_team, + 'PerMode': per_mode, + 'Season': season, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'LastNGames': last_n_games, + 'GameScope': game_scope, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'StarterBench': starter_bench, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight + }) + + def overall(self): + return _api_scrape(self.json, 0) + + +class PlayerSpeedDistanceTracking(_PlayerTrackingStats): + """ + Statistics that measure the distance covered and the average speed of all + movements (sprinting, jogging, standing, walking, backwards and forwards) + by a player while on the court. + """ + _pt_measure_type=PtMeasureType.SpeedDistance + +class PlayerTracking_Drives(_PlayerTrackingStats): + """ + Statistics that measure drives by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Drives + + +class PlayerTracking_Defense(_PlayerTrackingStats): + """ + Statistics that measure defense by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Defense + + + +class PlayerTracking_CatchShoot(_PlayerTrackingStats): + """ + Statistics that measure catch and shoot shooting by a player while on the court. + """ + _pt_measure_type=PtMeasureType.CatchShoot + + +class PlayerTracking_Passing(_PlayerTrackingStats): + """ + Statistics that measure passing by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Passing + + +class PlayerTracking_Possessions(_PlayerTrackingStats): + """ + Statistics that measure possessions by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Possessions + + +class PlayerTracking_PullUpShot(_PlayerTrackingStats): + """ + Statistics that measure pull up shots by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PullUpShot + + + +class PlayerTracking_Rebounding(_PlayerTrackingStats): + """ + Statistics that measure rebounding by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Rebounding + +class PlayerTracking_Efficiency(_PlayerTrackingStats): + """ + Statistics that measure efficiency for a player while on the court. + """ + _pt_measure_type=PtMeasureType.Efficiency + + +class PlayerTracking_ElbowTouch(_PlayerTrackingStats): + """ + Statistics that measure elbow touches by a player while on the court. + """ + _pt_measure_type=PtMeasureType.ElbowTouch + + +class PlayerTracking_PostTouch(_PlayerTrackingStats): + """ + Statistics that measure touches in the post by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PostTouch + + +class PlayerTracking_PaintTouch(_PlayerTrackingStats): + """ + Statistics that measure touches in the paint by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PaintTouch + +class GameLog: + _endpoint = 'leaguegamelog' + + def __init__(self, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + player_or_team=Player_or_Team.Default, + counter=Counter.Default, + sorter=Sorter.Default, + direction=Direction.Default, + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'PlayerOrTeam': player_or_team, + 'Counter': counter, + 'Sorter': sorter, + 'Direction': direction + }) + + def overall(self): + return _api_scrape(self.json, 0) diff --git a/nba_py/__init__.py b/nba_py/__init__.py index d15a964..87f438d 100644 --- a/nba_py/__init__.py +++ b/nba_py/__init__.py @@ -1,8 +1,7 @@ -from datetime import datetime, timedelta -import os - from requests import get +from datetime import datetime, timedelta from nba_py.constants import League +import os HAS_PANDAS = True try: @@ -22,13 +21,10 @@ # Constants TODAY = datetime.today() BASE_URL = 'http://stats.nba.com/stats/{endpoint}' -HEADERS = { - 'user-agent': ('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'), # noqa: E501 - 'Dnt': ('1'), - 'Accept-Encoding': ('gzip, deflate, sdch'), - 'Accept-Language': ('en'), - 'origin': ('http://stats.nba.com') - } +HEADERS = {'user-agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/45.0.2454.101 Safari/537.36'), + } def _api_scrape(json_inp, ndx): diff --git a/nba_py/constants.py b/nba_py/constants.py index 7e2c317..e8a5bf7 100644 --- a/nba_py/constants.py +++ b/nba_py/constants.py @@ -1,10 +1,4 @@ -from datetime import datetime - -_curr_year = datetime.now().year -if datetime.now().month > 6: - CURRENT_SEASON = str(_curr_year) + "-" + str(_curr_year + 1)[2:] -else: - CURRENT_SEASON = str(_curr_year - 1) + "-" + str(_curr_year)[2:] +CURRENT_SEASON = '2017-18' TEAMS = { 'ATL': { @@ -419,10 +413,19 @@ class MeasureType: Usage = 'Usage' Default = Base - class PtMeasureType: SpeedDistance = 'SpeedDistance' - + Drives = 'Drives' + Defense = 'Defense' + CatchShoot = 'CatchShoot' + Passing = 'Passing' + Possessions = 'Possessions' + PullUpShot = 'PullUpShot' + Rebounding = 'Rebounding' + Efficiency = 'Efficiency' + ElbowTouch = 'ElbowTouch' + PostTouch = 'PostTouch' + PaintTouch = 'PaintTouch' class GroupQuantity: Default = 5 @@ -614,8 +617,7 @@ class StatCategory: class ContextMeasure: - # Not sure if this is mapped correctly. Source: - # https://github.com/bradleyfay/NBAStats + # Not sure if this is mapped correctly. Source: https://github.com/bradleyfay/NBAStats FGM = 'FGM' FGA = 'FGA' FG_PCT = 'FG_PCT' diff --git a/nba_py/draftcombine.py b/nba_py/draftcombine.py index fe631a0..7f42796 100644 --- a/nba_py/draftcombine.py +++ b/nba_py/draftcombine.py @@ -1,14 +1,11 @@ from nba_py import _api_scrape, _get_json -from nba_py import constants +from nba_py.constants import * class Summary: _endpoint = 'draftcombinestats' - def __init__( - self, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON): + def __init__(self, league_id=League.Default, season=CURRENT_SEASON): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, 'SeasonYear': season}) @@ -20,10 +17,7 @@ def overall(self): class DrillResults: _endpoint = 'draftcombinedrillresults' - def __init__( - self, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON): + def __init__(self, league_id=League.Default, season=CURRENT_SEASON): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, 'SeasonYear': season}) @@ -35,10 +29,7 @@ def overall(self): class SpotShooting: _endpoint = 'draftcombinespotshooting' - def __init__( - self, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON): + def __init__(self, league_id=League.Default, season=CURRENT_SEASON): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, 'SeasonYear': season}) diff --git a/nba_py/game.py b/nba_py/game.py index 8af36ca..b9b805c 100644 --- a/nba_py/game.py +++ b/nba_py/game.py @@ -1,5 +1,5 @@ from nba_py import _api_scrape, _get_json -from nba_py import constants +from nba_py.constants import * class BoxscoreSummary: @@ -7,13 +7,13 @@ class BoxscoreSummary: def __init__(self, game_id, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - range_type=constants.RangeType.Default, - start_period=constants.StartPeriod.Default, - end_period=constants.EndPeriod.Default, - start_range=constants.StartRange.Default, - end_range=constants.EndRange.Default): + season=CURRENT_SEASON, + season_type=SeasonType.Default, + range_type=RangeType.Default, + start_period=StartPeriod.Default, + end_period=EndPeriod.Default, + start_range=StartRange.Default, + end_range=EndRange.Default): self.json = _get_json(endpoint=self._endpoint, params={'GameID': game_id, 'Season': season, @@ -51,18 +51,17 @@ def season_series(self): def available_video(self): return _api_scrape(self.json, 8) - class _BaseBoxcore: def __init__(self, game_id, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - range_type=constants.RangeType.Default, - start_period=constants.StartPeriod.Default, - end_period=constants.EndPeriod.Default, - start_range=constants.StartRange.Default, - end_range=constants.EndRange.Default): + season=CURRENT_SEASON, + season_type=SeasonType.Default, + range_type=RangeType.Default, + start_period=StartPeriod.Default, + end_period=EndPeriod.Default, + start_range=StartRange.Default, + end_range=EndRange.Default): self.json = _get_json(endpoint=self._endpoint, params={'GameID': game_id, 'Season': season, @@ -154,8 +153,8 @@ class PlayByPlay: def __init__(self, game_id, - start_period=constants.StartPeriod.Default, - end_period=constants.EndPeriod.Default): + start_period=StartPeriod.Default, + end_period=EndPeriod.Default): self.json = _get_json(endpoint=self._endpoint, params={'GameID': game_id, 'StartPeriod': start_period, @@ -166,8 +165,10 @@ def info(self): def available_video(self): return _api_scrape(self.json, 1) - - + + + + class HustleStats: _endpoint = 'hustlestatsboxscore' diff --git a/nba_py/league.py b/nba_py/league.py index 2aef748..6e51ddc 100644 --- a/nba_py/league.py +++ b/nba_py/league.py @@ -1,17 +1,17 @@ from nba_py import _api_scrape, _get_json -from nba_py import constants +from nba_py.constants import * class Leaders: _endpoint = 'leagueleaders' def __init__(self, - league_id=constants.League.Default, - per_mode=constants.PerMode.Default, - stat_category=constants.StatCategory.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - scope=constants.Scope.Default,): + league_id=League.Default, + per_mode=PerMode.Default, + stat_category=StatCategory.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + scope=Scope.Default,): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, 'PerMode': per_mode, @@ -28,13 +28,13 @@ class LeadersTiles: _endpoint = 'leaderstiles' def __init__(self, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - game_scope=constants.GameScope.Default, - player_scope=constants.PlayerScope.Default, - player_or_team=constants.PlayerOrTeam.Default, - stat_category=constants.StatCategory.Default): + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + game_scope=GameScope.Default, + player_scope=PlayerScope.Default, + player_or_team=PlayerOrTeam.Default, + stat_category=StatCategory.Default): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, 'Stat': stat_category, @@ -61,26 +61,26 @@ class Lineups: _endpoint = 'leaguedashlineups' def __init__(self, - group_quantity=constants.GroupQuantity.Default, - season_type=constants.SeasonType.Default, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.Rank.Default, - season=constants.CURRENT_SEASON, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - last_n_games=constants.LastNGames.Default): + group_quantity=GroupQuantity.Default, + season_type=SeasonType.Default, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'GroupQuantity': group_quantity, 'SeasonType': season_type, @@ -106,40 +106,39 @@ def __init__(self, def overall(self): return _api_scrape(self.json, 0) - class TeamStats: _endpoint = 'leaguedashteamstats' def __init__(self, - conference=constants.Conference.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - division=constants.Division.Default, - game_scope=constants.Game_Scope.Default, - game_segment=constants.GameSegment.Default, - last_n_games=constants.LastNGames.Default, - league_id=constants.League.Default, - location=constants.Location.Default, - measure_type=constants.MeasureType.Default, - month=constants.Month.Default, - opponent_team_id=constants.OpponentTeamID.Default, - outcome=constants.Outcome.Default, - playoff_round=constants.PlayoffRound.Default, - pace_adjust=constants.PaceAdjust.Default, - per_mode=constants.PerMode.Default, - period=constants.Period.Default, - player_experience=constants.PlayerExperience.Default, - player_position=constants.PlayerPosition.Default, - plus_minus=constants.PlusMinus.Default, - rank=constants.Rank.Default, - season=constants.CURRENT_SEASON, - season_segment=constants.SeasonSegment.Default, - season_type=constants.SeasonType.Default, - shot_clock_range=constants.ShotClockRange.Default, - starter_bench=constants.StarterBench.Default, - team_id=constants.TeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default + conference=Conference.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + division=Division.Default, + game_scope=Game_Scope.Default, + game_segment=GameSegment.Default, + last_n_games=LastNGames.Default, + league_id=League.Default, + location=Location.Default, + measure_type=MeasureType.Default, + month=Month.Default, + opponent_team_id=OpponentTeamID.Default, + outcome=Outcome.Default, + playoff_round=PlayoffRound.Default, + pace_adjust=PaceAdjust.Default, + per_mode=PerMode.Default, + period=Period.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + plus_minus=PlusMinus.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + season_segment=SeasonSegment.Default, + season_type=SeasonType.Default, + shot_clock_range=ShotClockRange.Default, + starter_bench=StarterBench.Default, + team_id=TeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default ): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, @@ -181,40 +180,40 @@ class PlayerStats: _endpoint = 'leaguedashplayerstats' def __init__(self, - season_type=constants.SeasonType.Default, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.Rank.Default, - season=constants.CURRENT_SEASON, - playoff_round=constants.PlayoffRound.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - team_id=constants.TeamID.Default, - conference=constants.Conference.Default, - division=constants.Division.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - shot_clock_range=constants.ShotClockRange.Default, - last_n_games=constants.LastNGames.Default, - game_scope=constants.Game_Scope.Default, - player_experience=constants.PlayerExperience.Default, - player_position=constants.PlayerPosition.Default, - starter_bench=constants.StarterBench.Default, - draft_year=constants.DraftYear.Default, - draft_pick=constants.DraftPick.Default, - college=constants.College.Default, - country=constants.Country.Default, - height=constants.Height.Default, - weight=constants.Weight.Default + season_type=SeasonType.Default, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + season=CURRENT_SEASON, + playoff_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + team_id=TeamID.Default, + conference=Conference.Default, + division=Division.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default, + game_scope=Game_Scope.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + starter_bench=StarterBench.Default, + draft_year=DraftYear.Default, + draft_pick=DraftPick.Default, + college=College.Default, + country=Country.Default, + height=Height.Default, + weight=Weight.Default ): self.json = _get_json(endpoint=self._endpoint, params={'SeasonType': season_type, @@ -297,35 +296,35 @@ class _PlayerTrackingStats: _pt_measure_type = '' def __init__(self, - league_id=constants.League.Default, - season_type=constants.SeasonType.Default, - player_or_team=constants.PlayerOrTeam.Default, - per_mode=constants.PerMode.Default, - season=constants.CURRENT_SEASON, - playoff_round=constants.PlayoffRound.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - team_id=constants.TeamID.Default, - conference=constants.Conference.Default, - division=constants.Division.Default, - last_n_games=constants.LastNGames.Default, - game_scope=constants.Game_Scope.Default, - player_experience=constants.PlayerExperience.Default, - player_position=constants.PlayerPosition.Default, - starter_bench=constants.StarterBench.Default, - draft_year=constants.DraftYear.Default, - draft_pick=constants.DraftPick.Default, - college=constants.College.Default, - country=constants.Country.Default, - height=constants.Height.Default, - weight=constants.Weight.Default + league_id=League.Default, + season_type=SeasonType.Default, + player_or_team=PlayerOrTeam.Default, + per_mode=PerMode.Default, + season=CURRENT_SEASON, + playoff_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + team_id=TeamID.Default, + conference=Conference.Default, + division=Division.Default, + last_n_games=LastNGames.Default, + game_scope=Game_Scope.Default, + player_experience=PlayerExperience.Default, + player_position=PlayerPosition.Default, + starter_bench=StarterBench.Default, + draft_year=DraftYear.Default, + draft_pick=DraftPick.Default, + college=College.Default, + country=Country.Default, + height=Height.Default, + weight=Weight.Default ): self.json = _get_json(endpoint=self._endpoint, @@ -371,20 +370,96 @@ class PlayerSpeedDistanceTracking(_PlayerTrackingStats): movements (sprinting, jogging, standing, walking, backwards and forwards) by a player while on the court. """ - _pt_measure_type = constants.PtMeasureType.SpeedDistance + _pt_measure_type=PtMeasureType.SpeedDistance + +class PlayerTracking_Drives(_PlayerTrackingStats): + """ + Statistics that measure drives by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Drives + + +class PlayerTracking_Defense(_PlayerTrackingStats): + """ + Statistics that measure defense by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Defense + + + +class PlayerTracking_CatchShoot(_PlayerTrackingStats): + """ + Statistics that measure catch and shoot shooting by a player while on the court. + """ + _pt_measure_type=PtMeasureType.CatchShoot + + +class PlayerTracking_Passing(_PlayerTrackingStats): + """ + Statistics that measure passing by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Passing + + +class PlayerTracking_Possessions(_PlayerTrackingStats): + """ + Statistics that measure possessions by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Possessions + + +class PlayerTracking_PullUpShot(_PlayerTrackingStats): + """ + Statistics that measure pull up shots by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PullUpShot + + + +class PlayerTracking_Rebounding(_PlayerTrackingStats): + """ + Statistics that measure rebounding by a player while on the court. + """ + _pt_measure_type=PtMeasureType.Rebounding + +class PlayerTracking_Efficiency(_PlayerTrackingStats): + """ + Statistics that measure efficiency for a player while on the court. + """ + _pt_measure_type=PtMeasureType.Efficiency +class PlayerTracking_ElbowTouch(_PlayerTrackingStats): + """ + Statistics that measure elbow touches by a player while on the court. + """ + _pt_measure_type=PtMeasureType.ElbowTouch + + +class PlayerTracking_PostTouch(_PlayerTrackingStats): + """ + Statistics that measure touches in the post by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PostTouch + + +class PlayerTracking_PaintTouch(_PlayerTrackingStats): + """ + Statistics that measure touches in the paint by a player while on the court. + """ + _pt_measure_type=PtMeasureType.PaintTouch + class GameLog: _endpoint = 'leaguegamelog' def __init__(self, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - player_or_team=constants.Player_or_Team.Default, - counter=constants.Counter.Default, - sorter=constants.Sorter.Default, - direction=constants.Direction.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + player_or_team=Player_or_Team.Default, + counter=Counter.Default, + sorter=Sorter.Default, + direction=Direction.Default, ): self.json = _get_json(endpoint=self._endpoint, diff --git a/nba_py/player.py b/nba_py/player.py index fa9ca84..f519941 100644 --- a/nba_py/player.py +++ b/nba_py/player.py @@ -1,5 +1,5 @@ -from nba_py import _api_scrape, _get_json, HAS_PANDAS -from nba_py import constants +from nba_py import _api_scrape, _get_json, HAS_PANDAS, constants +from nba_py.constants import * class PlayerNotFoundException(Exception): @@ -7,8 +7,8 @@ class PlayerNotFoundException(Exception): def get_player(first_name, - last_name=None, - season=constants.CURRENT_SEASON, + last_name = None, + season=CURRENT_SEASON, only_current=0, just_id=True): """ @@ -17,8 +17,7 @@ def get_player(first_name, Args: :first_name: First name of the player - :last_name: Last name of the player - (this is None if the player only has first name [Nene]) + :last_name: Last name of the player (this is None if the player only has first name [Nene]) :only_current: Only wants the current list of players :just_id: Only wants the id of the player @@ -62,8 +61,8 @@ class PlayerList: _endpoint = 'commonallplayers' def __init__(self, - league_id=constants.League.NBA, - season=constants.CURRENT_SEASON, + league_id=League.NBA, + season=CURRENT_SEASON, only_current=1): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, @@ -98,22 +97,229 @@ def headline_stats(self): return _api_scrape(self.json, 1) -class _PlayerDashboard: +class PlayerNextNGames: """ - Has all the basic arguments for all of the Player Dashboard type objects + Contains information about upcoming games for a player Args: :player_id: ID of the player to look up - :team_id: ID of the team to look up + :number_of_games: Number of future games to look up + :season: Season given to look up + :season_type: Season type to consider (Regular / Playoffs) + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playernextngames' + + def __init__(self, + player_id, + number_of_games, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default): + self.json = _get_json(endpoint=self._endpoint, + params={'PlayerID': player_id, + 'NumberOfGames': number_of_games, + 'Season': season, + 'SeasonType': season_type}) + + def info(self): + return _api_scrape(self.json, 0) + + +class PlayerFantasyBarGraph: + """ + Fantasy information that can be presented in bar graphs + + Args: + :player_id: ID of the player to look up + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular / Playoffs) + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playerfantasyprofilebargraph' + + def __init__(self, + player_id, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default): + self.json = _get_json(endpoint=self._endpoint, + params={'PlayerID': player_id, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type}) + + def info(self): + return _api_scrape(self.json, 0) + + def last_five_games(self): + return _api_scrape(self.json, 1) + + +class PlayerFantasyProfile: + """ + Contains fantasy player information + + Args: + :player_id: ID of the player to look up + :league_id: ID for the league to look in (Default is 00) :measure_type: Specifies type of measure to use (Base, Advanced, etc.) :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) :plus_minus: Whether or not to consider plus minus (Y or N) :pace_adjust: Whether or not to pace adjust stats (Y or N) :rank: Whether or not to consider rank (Y or N) + :season: Season given to look up + :season_type: Season type to consider (Regular / Playoffs) + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playerfantasyprofile' + + def __init__(self, + player_id, + league_id=constants.League.Default, + measure_type=constants.MeasureType.Default, + per_mode=constants.PerMode.Default, + plus_minus=constants.PlusMinus.Default, + pace_adjust=constants.PaceAdjust.Default, + rank=constants.PaceAdjust.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default,): + self.json = _get_json(endpoint=self._endpoint, + params={'PlayerID': player_id, + 'LeagueID': league_id, + 'MeasureType': measure_type, + 'PerMode': per_mode, + 'PlusMinus': plus_minus, + 'PaceAdjust': pace_adjust, + 'Rank': rank, + 'Season': season, + 'SeasonType': season_type}) + + def overall(self): + return _api_scrape(self.json, 0) + + def location(self): + return _api_scrape(self.json, 1) + + def LastNGames(self): + return _api_scrape(self.json, 2) + + def DaysRestModified(self): + return _api_scrape(self.json, 3) + + def Opponent(self): + return _api_scrape(self.json, 4) + + +class PlayerCareerByCollegeRollup: + """ + Contains div1 college team totals sorted by last year's seeding + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) :league_id: ID for the league to look in (Default is 00) :season: Season given to look up :season_type: Season type to consider (Regular / Playoffs) - :po_round: Playoff round + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playercareerbycollegerollup' + + def __init__(self, + per_mode=constants.PerMode.Default, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default): + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type}) + + def east(self): + return _api_scrape(self.json, 0) + + def south(self): + return _api_scrape(self.json, 1) + + def midwest(self): + return _api_scrape(self.json, 2) + + def west(self): + return _api_scrape(self.json, 3) + + +class PlayerCareerByCollege: + """ + Contains list of nba players and their nba stats grouped by their college + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular / Playoffs) + :college: which college the player attended (Duke, UCLA etc.) + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playercareerbycollege' + + def __init__(self, + per_mode=constants.PerMode.Default, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default, + college=0): + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'College': college}) + + def info(self): + return _api_scrape(self.json, 0) + + +class PlayerAwards: + """ + Contains information on all awards given to a player (player_id) + + Args: + :player_id: ID of the player to look up + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = 'playerawards' + + def __init__(self, + player_id): + self.json = _get_json(endpoint=self._endpoint, + params={'PlayerID': player_id}) + + def info(self): + return _api_scrape(self.json, 0) + + +class PlayerHustleLeaders: + """ + Contains league leading hustle stats by player + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular or Playoffs) + :playoff_round: Playoff round :outcome: Filter out by wins or losses :location: Filter out by home or away :month: Specify month to filter by @@ -123,28 +329,132 @@ class _PlayerDashboard: :opponent_team_id: Opponent team ID to look up :vs_conference: Filter by conference :vs_division: Filter by division - :game_segment: Filter by half / overtime - :period: Filter by quarter / specific overtime - :shot_clock_range: Filter statistics by range in shot clock - :last_n_games: Filter by number of games specified in N + :team_id: ID of the team to look up + :conference: Filter by conference + :division: Filter by division + :player_experience: Player experience (Rookie + :player_position: Filter by position (Forward + :draft_year: Filter by draft year + :draft_pick: Filter by draft pick (1st+Round, Lottery+Pick, etc.) + :college: Filter by college + :country: Filter by country + :height: Filter by player's height + :weight: Filter by player's weight + """ - Attributes: - :json: Contains the full json dump to play around with + _endpoint = 'leaguehustlestatsplayerleaders' + + def __init__(self, + per_mode=constants.PerMode.Default, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default, + playoff_round=constants.PlayoffRound.Default, + outcome=constants.Outcome.Default, + location=constants.Location.Default, + month=constants.Month.Default, + season_segment=constants.SeasonSegment.Default, + date_from=constants.DateFrom.Default, + date_to=constants.DateTo.Default, + opponent_team_id=constants.OpponentTeamID.Default, + vs_conference=constants.VsConference.Default, + vs_division=constants.VsDivision.Default, + team_id=constants.TeamID.Default, + conference=constants.Conference.Default, + division=constants.Division.Default, + player_experience=constants.PlayerExperience.Default, + player_position=constants.PlayerPosition.Default, + draft_year=constants.DraftYear.Default, + draft_pick=constants.DraftPick.Default, + college=constants.College.Default, + country=constants.Country.Default, + height=constants.Height.Default, + weight=constants.Weight.Default + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight}) + + def contested_shots(self): + return _api_scrape(self.json, 0) + + def charges_drawn(self): + return _api_scrape(self.json, 1) + + def deflections(self): + return _api_scrape(self.json, 2) + + def loose_balls(self): + return _api_scrape(self.json, 3) + + def screen_assists(self): + return _api_scrape(self.json, 4) + + +class PlayerHustleStats: """ - _endpoint = 'playerdashboardbyyearoveryear' + Contains hustle stats by player + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular or Playoffs) + :playoff_round: Playoff round + :outcome: Filter out by wins or losses + :location: Filter out by home or away + :month: Specify month to filter by + :season_segment: Filter by pre/post all star break + :date_from: Filter out games before a specific date + :date_to: Filter out games after a specific date + :opponent_team_id: Opponent team ID to look up + :vs_conference: Filter by conference + :vs_division: Filter by division + :team_id: ID of the team to look up + :conference: Filter by conference + :division: Filter by division + :player_experience: Player experience (Rookie + :player_position: Filter by position (Forward + :draft_year: Filter by draft year + :draft_pick: Filter by draft pick (1st+Round, Lottery+Pick, etc.) + :college: Filter by college + :country: Filter by country + :height: Filter by player's height + :weight: Filter by player's weight + """ + + _endpoint = 'leaguehustlestatsplayer' def __init__(self, - player_id, - team_id=0, - measure_type=constants.MeasureType.Default, per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.PaceAdjust.Default, league_id=constants.League.Default, season=constants.CURRENT_SEASON, season_type=constants.SeasonType.Default, - po_round=constants.PlayoffRound.Default, + playoff_round=constants.PlayoffRound.Default, outcome=constants.Outcome.Default, location=constants.Location.Default, month=constants.Month.Default, @@ -154,10 +464,110 @@ def __init__(self, opponent_team_id=constants.OpponentTeamID.Default, vs_conference=constants.VsConference.Default, vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - shot_clock_range=constants.ShotClockRange.Default, - last_n_games=constants.LastNGames.Default): + team_id=constants.TeamID.Default, + conference=constants.Conference.Default, + division=constants.Division.Default, + player_experience=constants.PlayerExperience.Default, + player_position=constants.PlayerPosition.Default, + draft_year=constants.DraftYear.Default, + draft_pick=constants.DraftPick.Default, + college=constants.College.Default, + country=constants.Country.Default, + height=constants.Height.Default, + weight=constants.Weight.Default + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight}) + + def info(self): + return _api_scrape(self.json, 0) + + +class _PlayerDashboard: + """ + Has all the basic arguments for all of the Player Dashboard type objects + + Args: + :player_id: ID of the player to look up + :team_id: ID of the team to look up + :measure_type: Specifies type of measure to use (Base, Advanced, etc.) + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :plus_minus: Whether or not to consider plus minus (Y or N) + :pace_adjust: Whether or not to pace adjust stats (Y or N) + :rank: Whether or not to consider rank (Y or N) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular / Playoffs) + :po_round: Playoff round + :outcome: Filter out by wins or losses + :location: Filter out by home or away + :month: Specify month to filter by + :season_segment: Filter by pre/post all star break + :date_from: Filter out games before a specific date + :date_to: Filter out games after a specific date + :opponent_team_id: Opponent team ID to look up + :vs_conference: Filter by conference + :vs_division: Filter by division + :game_segment: Filter by half / overtime + :period: Filter by quarter / specific overtime + :shot_clock_range: Filter statistics by range in shot clock + :last_n_games: Filter by number of games specified in N + + Attributes: + :json: Contains the full json dump to play around with + """ + _endpoint = '' + + def __init__(self, + player_id, + team_id=0, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=PaceAdjust.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + po_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'PlayerID': player_id, 'TeamID': team_id, @@ -183,7 +593,7 @@ def __init__(self, 'Period': period, 'ShotClockRange': shot_clock_range, 'LastNGames': last_n_games}, - referer='player') + referer='player') def overall(self): return _api_scrape(self.json, 0) @@ -538,7 +948,7 @@ def shot_types_summary(self): def shot_types_detail(self): return _api_scrape(self.json, 6) - def assisted_by(self): + def assissted_by(self): return _api_scrape(self.json, 7) @@ -646,8 +1056,8 @@ class PlayerCareer: def __init__(self, player_id, - per_mode=constants.PerMode.PerGame, - league_id=constants.League.NBA): + per_mode=PerMode.PerGame, + league_id=League.NBA): self.json = _get_json(endpoint=self._endpoint, params={'PlayerID': player_id, 'LeagueID': league_id, @@ -677,17 +1087,11 @@ def college_season_totals(self): def college_season_career_totals(self): return _api_scrape(self.json, 7) - def preseason_season_totals(self): - return _api_scrape(self.json, 8) - - def preseason_career_totals(self): - return _api_scrape(self.json, 9) - def regular_season_rankings(self): - return _api_scrape(self.json, 10) + return _api_scrape(self.json, 8) def post_season_rankings(self): - return _api_scrape(self.json, 11) + return _api_scrape(self.json, 9) class PlayerProfile(PlayerCareer): @@ -706,13 +1110,13 @@ class PlayerProfile(PlayerCareer): _endpoint = 'playerprofilev2' def season_highs(self): - return _api_scrape(self.json, 12) + return _api_scrape(self.json, 10) def career_highs(self): - return _api_scrape(self.json, 13) + return _api_scrape(self.json, 11) def next_game(self): - return _api_scrape(self.json, 14) + return _api_scrape(self.json, 12) class PlayerGameLogs: @@ -732,9 +1136,9 @@ class PlayerGameLogs: def __init__(self, player_id, - league_id=constants.League.NBA, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Regular): + league_id=League.NBA, + season=CURRENT_SEASON, + season_type=SeasonType.Regular): self.json = _get_json(endpoint=self._endpoint, params={'PlayerID': player_id, 'LeagueID': league_id, @@ -887,7 +1291,7 @@ class PlayerPassTracking(_PlayerDashboard): def passes_made(self): return _api_scrape(self.json, 0) - def passes_received(self): + def passes_recieved(self): return _api_scrape(self.json, 1) @@ -1039,28 +1443,28 @@ def __init__(self, player_id, vs_player_id, team_id=0, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.PaceAdjust.Default, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - po_round=constants.PlayoffRound.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - shot_clock_range=constants.ShotClockRange.Default, - last_n_games=constants.LastNGames.Default): + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=PaceAdjust.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + po_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'PlayerID': player_id, 'VsPlayerID': vs_player_id, diff --git a/nba_py/shotchart.py b/nba_py/shotchart.py index fed3b94..689c278 100644 --- a/nba_py/shotchart.py +++ b/nba_py/shotchart.py @@ -1,59 +1,58 @@ from nba_py import _api_scrape, _get_json -from nba_py import constants - +from nba_py.constants import * class ShotChart: _endpoint = 'shotchartdetail' def __init__(self, player_id, - team_id=constants.TeamID.Default, - game_id=constants.GameID.Default, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conf=constants.VsConference.Default, - vs_div=constants.VsDivision.Default, - position=constants.PlayerPosition.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - last_n_games=constants.LastNGames.Default, - ahead_behind=constants.AheadBehind.Default, - context_measure=constants.ContextMeasure.Default, - clutch_time=constants.ClutchTime.Default, - rookie_year=constants.RookieYear.Default): + team_id=TeamID.Default, + game_id=GameID.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conf = VsConference.Default, + vs_div = VsDivision.Default, + position = PlayerPosition.Default, + game_segment=GameSegment.Default, + period=Period.Default, + last_n_games=LastNGames.Default, + ahead_behind=AheadBehind.Default, + context_measure=ContextMeasure.Default, + clutch_time=ClutchTime.Default, + rookie_year=RookieYear.Default): self.json = _get_json(endpoint=self._endpoint, - params={'PlayerID': player_id, - 'TeamID': team_id, - 'GameID': game_id, + params={'PlayerID' : player_id, + 'TeamID' : team_id, + 'GameID' : game_id, 'LeagueID': league_id, - 'Season': season, - 'SeasonType': season_type, - 'Outcome': outcome, - 'Location': location, - 'Month': month, - 'SeasonSegment': season_segment, - 'DateFrom': date_from, - 'DateTo': date_to, - 'OpponentTeamID': opponent_team_id, - 'VsConference': vs_conf, - 'VsDivision': vs_div, - 'PlayerPosition': position, - 'GameSegment': game_segment, - 'Period': period, - 'LastNGames': last_n_games, - 'AheadBehind': ahead_behind, - 'ContextMeasure': context_measure, - 'ClutchTime': clutch_time, - 'RookieYear': rookie_year}) + 'Season' : season, + 'SeasonType' : season_type, + 'Outcome' : outcome, + 'Location' : location, + 'Month' : month, + 'SeasonSegment' : season_segment, + 'DateFrom' : date_from, + 'DateTo' : date_to, + 'OpponentTeamID' : opponent_team_id, + 'VsConference' : vs_conf, + 'VsDivision' : vs_div, + 'PlayerPosition' : position, + 'GameSegment' : game_segment, + 'Period' : period, + 'LastNGames' : last_n_games, + 'AheadBehind' : ahead_behind, + 'ContextMeasure' : context_measure, + 'ClutchTime' : clutch_time, + 'RookieYear' : rookie_year}) def shot_chart(self): return _api_scrape(self.json, 0) diff --git a/nba_py/team.py b/nba_py/team.py index adcf03d..90caf25 100644 --- a/nba_py/team.py +++ b/nba_py/team.py @@ -1,12 +1,12 @@ -from nba_py import _api_scrape, _get_json -from nba_py import constants +from nba_py import _api_scrape, _get_json, constants +from nba_py.constants import * class TeamList: _endpoint = 'commonteamyears' def __init__(self, - league_id=constants.League.NBA): + league_id=League.NBA): self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id}) @@ -19,9 +19,9 @@ class TeamSummary: def __init__(self, team_id, - season=constants.CURRENT_SEASON, - league_id=constants.League.NBA, - season_type=constants.SeasonType.Default): + season=CURRENT_SEASON, + league_id=League.NBA, + season_type=SeasonType.Default): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'Season': season, @@ -72,7 +72,7 @@ class TeamCommonRoster: def __init__(self, team_id, - season=constants.CURRENT_SEASON): + season=CURRENT_SEASON): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'Season': season}) @@ -89,28 +89,28 @@ class _TeamDashboard: def __init__(self, team_id, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.Rank.Default, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - po_round=constants.PlayoffRound.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - shot_clock_range=constants.ShotClockRange.Default, - last_n_games=constants.LastNGames.Default): + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + po_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'MeasureType': measure_type, @@ -169,7 +169,7 @@ def by_division(self): return _api_scrape(self.json, 2) def by_opponent(self): - return _api_scrape(self.json, 3) + return _api_scrape(self.json, 2) class TeamLastNGamesSplits(_TeamDashboard): @@ -292,7 +292,7 @@ def assisted_shots(self): def shot_type_summary(self): return _api_scrape(self.json, 5) - def assisted_by(self): + def assissted_by(self): return _api_scrape(self.json, 6) @@ -322,26 +322,26 @@ class TeamLineups: def __init__(self, team_id, game_id='', - group_quantity=constants.GroupQuantity.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.Rank.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - last_n_games=constants.LastNGames.Default): + group_quantity=GroupQuantity.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'GroupQuantity': group_quantity, 'GameID': game_id, @@ -405,8 +405,8 @@ class TeamGameLogs: def __init__(self, team_id, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default): + season=CURRENT_SEASON, + season_type=SeasonType.Default): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'Season': season, @@ -421,9 +421,9 @@ class TeamSeasons: def __init__(self, team_id, - league_id=constants.League.NBA, - season_type=constants.SeasonType.Default, - per_mode=constants.PerMode.Default): + league_id=League.NBA, + season_type=SeasonType.Default, + per_mode=PerMode.Default): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'LeagueID': league_id, @@ -485,28 +485,28 @@ class TeamVsPlayer: def __init__(self, team_id, vs_player_id, - measure_type=constants.MeasureType.Default, - per_mode=constants.PerMode.Default, - plus_minus=constants.PlusMinus.Default, - pace_adjust=constants.PaceAdjust.Default, - rank=constants.Rank.Default, - league_id=constants.League.Default, - season=constants.CURRENT_SEASON, - season_type=constants.SeasonType.Default, - po_round=constants.PlayoffRound.Default, - outcome=constants.Outcome.Default, - location=constants.Location.Default, - month=constants.Month.Default, - season_segment=constants.SeasonSegment.Default, - date_from=constants.DateFrom.Default, - date_to=constants.DateTo.Default, - opponent_team_id=constants.OpponentTeamID.Default, - vs_conference=constants.VsConference.Default, - vs_division=constants.VsDivision.Default, - game_segment=constants.GameSegment.Default, - period=constants.Period.Default, - shot_clock_range=constants.ShotClockRange.Default, - last_n_games=constants.LastNGames.Default): + measure_type=MeasureType.Default, + per_mode=PerMode.Default, + plus_minus=PlusMinus.Default, + pace_adjust=PaceAdjust.Default, + rank=Rank.Default, + league_id=League.Default, + season=CURRENT_SEASON, + season_type=SeasonType.Default, + po_round=PlayoffRound.Default, + outcome=Outcome.Default, + location=Location.Default, + month=Month.Default, + season_segment=SeasonSegment.Default, + date_from=DateFrom.Default, + date_to=DateTo.Default, + opponent_team_id=OpponentTeamID.Default, + vs_conference=VsConference.Default, + vs_division=VsDivision.Default, + game_segment=GameSegment.Default, + period=Period.Default, + shot_clock_range=ShotClockRange.Default, + last_n_games=LastNGames.Default): self.json = _get_json(endpoint=self._endpoint, params={'TeamID': team_id, 'VsPlayerID': vs_player_id, @@ -559,3 +559,201 @@ def shot_area_on_court(self): def shot_area_off_court(self): return _api_scrape(self.json, 8) + + +class TeamHustleLeaders: + """ + Contains league leading hustle stats by team + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular or Playoffs) + :playoff_round: Playoff round + :outcome: Filter out by wins or losses + :location: Filter out by home or away + :month: Specify month to filter by + :season_segment: Filter by pre/post all star break + :date_from: Filter out games before a specific date + :date_to: Filter out games after a specific date + :opponent_team_id: Opponent team ID to look up + :vs_conference: Filter by conference + :vs_division: Filter by division + :team_id: ID of the team to look up + :conference: Filter by conference + :division: Filter by division + :player_experience: Player experience (Rookie + :player_position: Filter by position (Forward + :draft_year: Filter by draft year + :draft_pick: Filter by draft pick (1st+Round, Lottery+Pick, etc.) + :college: Filter by college + :country: Filter by country + :height: Filter by player's height + :weight: Filter by player's weight + """ + + _endpoint = 'leaguehustlestatsteamleaders' + + def __init__(self, + per_mode=constants.PerMode.Default, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default, + playoff_round=constants.PlayoffRound.Default, + outcome=constants.Outcome.Default, + location=constants.Location.Default, + month=constants.Month.Default, + season_segment=constants.SeasonSegment.Default, + date_from=constants.DateFrom.Default, + date_to=constants.DateTo.Default, + opponent_team_id=constants.OpponentTeamID.Default, + vs_conference=constants.VsConference.Default, + vs_division=constants.VsDivision.Default, + team_id=constants.TeamID.Default, + conference=constants.Conference.Default, + division=constants.Division.Default, + player_experience=constants.PlayerExperience.Default, + player_position=constants.PlayerPosition.Default, + draft_year=constants.DraftYear.Default, + draft_pick=constants.DraftPick.Default, + college=constants.College.Default, + country=constants.Country.Default, + height=constants.Height.Default, + weight=constants.Weight.Default + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight}) + + def contested_shots(self): + return _api_scrape(self.json, 0) + + def charges_drawn(self): + return _api_scrape(self.json, 1) + + def deflections(self): + return _api_scrape(self.json, 2) + + def loose_balls(self): + return _api_scrape(self.json, 3) + + def screen_assists(self): + return _api_scrape(self.json, 4) + + +class TeamHustleStats: + """ + Contains hustle stats by team + + Args: + :per_mode: Mode to measure statistics (Totals, PerGame, Per36, etc.) + :league_id: ID for the league to look in (Default is 00) + :season: Season given to look up + :season_type: Season type to consider (Regular or Playoffs) + :playoff_round: Playoff round + :outcome: Filter out by wins or losses + :location: Filter out by home or away + :month: Specify month to filter by + :season_segment: Filter by pre/post all star break + :date_from: Filter out games before a specific date + :date_to: Filter out games after a specific date + :opponent_team_id: Opponent team ID to look up + :vs_conference: Filter by conference + :vs_division: Filter by division + :team_id: ID of the team to look up + :conference: Filter by conference + :division: Filter by division + :player_experience: Player experience (Rookie + :player_position: Filter by position (Forward + :draft_year: Filter by draft year + :draft_pick: Filter by draft pick (1st+Round, Lottery+Pick, etc.) + :college: Filter by college + :country: Filter by country + :height: Filter by player's height + :weight: Filter by player's weight + """ + + _endpoint = 'leaguehustlestatsteam' + + def __init__(self, + per_mode=constants.PerMode.Default, + league_id=constants.League.Default, + season=constants.CURRENT_SEASON, + season_type=constants.SeasonType.Default, + playoff_round=constants.PlayoffRound.Default, + outcome=constants.Outcome.Default, + location=constants.Location.Default, + month=constants.Month.Default, + season_segment=constants.SeasonSegment.Default, + date_from=constants.DateFrom.Default, + date_to=constants.DateTo.Default, + opponent_team_id=constants.OpponentTeamID.Default, + vs_conference=constants.VsConference.Default, + vs_division=constants.VsDivision.Default, + team_id=constants.TeamID.Default, + conference=constants.Conference.Default, + division=constants.Division.Default, + player_experience=constants.PlayerExperience.Default, + player_position=constants.PlayerPosition.Default, + draft_year=constants.DraftYear.Default, + draft_pick=constants.DraftPick.Default, + college=constants.College.Default, + country=constants.Country.Default, + height=constants.Height.Default, + weight=constants.Weight.Default + ): + + self.json = _get_json(endpoint=self._endpoint, + params={'PerMode': per_mode, + 'LeagueID': league_id, + 'Season': season, + 'SeasonType': season_type, + 'PORound': playoff_round, + 'Outcome': outcome, + 'Location': location, + 'Month': month, + 'SeasonSegment': season_segment, + 'DateFrom': date_from, + 'DateTo': date_to, + 'OpponentTeamID': opponent_team_id, + 'VsConference': vs_conference, + 'VsDivision': vs_division, + 'TeamID': team_id, + 'Conference': conference, + 'Division': division, + 'PlayerExperience': player_experience, + 'PlayerPosition': player_position, + 'DraftYear': draft_year, + 'DraftPick': draft_pick, + 'College': college, + 'Country': country, + 'Height': height, + 'Weight': weight}) + + def info(self): + return _api_scrape(self.json, 0)