Best Python code snippet using ATX
_Player.py
Source:_Player.py
1import requests as _requests2from goldsberry._apiFunc import *3my_headers = {4 'Accept-Encoding': 'gzip, deflate, sdch',5 'Accept-Language': 'en-US,en;q=0.8',6 'Upgrade-Insecure-Requests': '1',7 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64)'\8 ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 '\9 'Safari/537.36',10 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9'\11 ',image/webp,*/*;q=0.8',12 'Cache-Control': 'max-age=0',13 'Connection': 'keep-alive'14}15class demographics:16 def __init__(self, playerid):17 self._url = 'http://stats.nba.com/stats/commonplayerinfo?'18 self._api_param = {'PlayerID':playerid}19 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)20 def player_info(self):21 _headers = self._pull.json()['resultSets'][0]['headers']22 _values = self._pull.json()['resultSets'][0]['rowSet']23 return [dict(zip(_headers, value)) for value in _values]24 def headline_stats(self):25 _headers = self._pull.json()['resultSets'][1]['headers']26 _values = self._pull.json()['resultSets'][1]['rowSet']27 return [dict(zip(_headers, value)) for value in _values]28class career_stats:29 def __init__(self, playerid, league='NBA',permode=1):30 self._url = "http://stats.nba.com/stats/playerprofilev2?"31 self._api_param = {'PlayerID':playerid,32 'LeagueID':_nbaLeague(league),33 'PerMode':_PerModeSmall36(permode)}34 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)35 def season_totals_regular(self):36 _headers = self._pull.json()['resultSets'][0]['headers']37 _values = self._pull.json()['resultSets'][0]['rowSet']38 return [dict(zip(_headers, value)) for value in _values]39 def career_totals_regular(self):40 _headers = self._pull.json()['resultSets'][1]['headers']41 _values = self._pull.json()['resultSets'][1]['rowSet']42 return [dict(zip(_headers, value)) for value in _values]43 def season_totals_post(self):44 _headers = self._pull.json()['resultSets'][2]['headers']45 _values = self._pull.json()['resultSets'][2]['rowSet']46 return [dict(zip(_headers, value)) for value in _values]47 def career_totals_post(self):48 _headers = self._pull.json()['resultSets'][3]['headers']49 _values = self._pull.json()['resultSets'][3]['rowSet']50 return [dict(zip(_headers, value)) for value in _values]51 def season_totals_allstar(self):52 _headers = self._pull.json()['resultSets'][4]['headers']53 _values = self._pull.json()['resultSets'][4]['rowSet']54 return [dict(zip(_headers, value)) for value in _values]55 def career_totals_allstar(self):56 _headers = self._pull.json()['resultSets'][5]['headers']57 _values = self._pull.json()['resultSets'][5]['rowSet']58 return [dict(zip(_headers, value)) for value in _values]59 def season_totals_college(self):60 _headers = self._pull.json()['resultSets'][6]['headers']61 _values = self._pull.json()['resultSets'][6]['rowSet']62 return [dict(zip(_headers, value)) for value in _values]63 def career_totals_college(self):64 _headers = self._pull.json()['resultSets'][7]['headers']65 _values = self._pull.json()['resultSets'][7]['rowSet']66 return [dict(zip(_headers, value)) for value in _values]67 def season_rankings_regular(self):68 _headers = self._pull.json()['resultSets'][8]['headers']69 _values = self._pull.json()['resultSets'][8]['rowSet']70 return [dict(zip(_headers, value)) for value in _values]71 def season_rankings_post(self):72 _headers = self._pull.json()['resultSets'][9]['headers']73 _values = self._pull.json()['resultSets'][9]['rowSet']74 return [dict(zip(_headers, value)) for value in _values]75 def season_high(self):76 _headers = self._pull.json()['resultSets'][10]['headers']77 _values = self._pull.json()['resultSets'][10]['rowSet']78 return [dict(zip(_headers, value)) for value in _values]79 def career_high(self):80 _headers = self._pull.json()['resultSets'][11]['headers']81 _values = self._pull.json()['resultSets'][11]['rowSet']82 return [dict(zip(_headers, value)) for value in _values]83 def next_game(self):84 _headers = self._pull.json()['resultSets'][12]['headers']85 _values = self._pull.json()['resultSets'][12]['rowSet']86 return [dict(zip(_headers, value)) for value in _values]87class general_splits:88 def __init__(self, playerid, season='2015',seasontype=1, league='NBA',89 dateto='', datefrom='', gamesegment=1, lastngames=0, location=1, measuretype=1,90 month=0, opponentteamid=0, outcome=1, paceadjust=1, permode=1, period=0,91 plusminus=1, rank=1, seasonsegment=1, vsconf=1, vsdiv=1):92 self._url = "http://stats.nba.com/stats/playerdashboardbygeneralsplits?"93 self._api_param = {'PlayerID':playerid,94 'SeasonType': _SeasonType(seasontype),95 'Season': _nbaSeason(season),96 'LeagueID': _nbaLeague(league),97 'DateTo':_valiDate(dateto),98 'DateFrom':_valiDate(datefrom),99 'GameSegment':_GameSegment(gamesegment),100 'LastNGames':lastngames,101 'Location':_Location(location),102 'MeasureType':_measureType(measuretype),103 'Month':month,104 'OpponentTeamID':opponentteamid,105 'Outcome':_Outcome(outcome),106 'PaceAdjust':_PaceAdjust(paceadjust),107 'PerMode':_PerModeLarge(permode),108 'Period':period,109 'PlusMinus':_PlusMinus(plusminus),110 'Rank':_Rank(rank),111 'SeasonSegment':_SeasonSegment(seasonsegment),112 'VsConference':_VsConference(vsconf),113 'VsDivision':_VsDivision(vsdiv)}114 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)115 def overall(self):116 _headers = self._pull.json()['resultSets'][0]['headers']117 _values = self._pull.json()['resultSets'][0]['rowSet']118 return [dict(zip(_headers, value)) for value in _values]119 def location(self):120 _headers = self._pull.json()['resultSets'][1]['headers']121 _values = self._pull.json()['resultSets'][1]['rowSet']122 return [dict(zip(_headers, value)) for value in _values]123 def wins_losses(self):124 _headers = self._pull.json()['resultSets'][2]['headers']125 _values = self._pull.json()['resultSets'][2]['rowSet']126 return [dict(zip(_headers, value)) for value in _values]127 def month(self):128 _headers = self._pull.json()['resultSets'][3]['headers']129 _values = self._pull.json()['resultSets'][3]['rowSet']130 return [dict(zip(_headers, value)) for value in _values]131 def pre_post_allstar(self):132 _headers = self._pull.json()['resultSets'][4]['headers']133 _values = self._pull.json()['resultSets'][4]['rowSet']134 return [dict(zip(_headers, value)) for value in _values]135 def starting_position(self):136 _headers = self._pull.json()['resultSets'][5]['headers']137 _values = self._pull.json()['resultSets'][5]['rowSet']138 return [dict(zip(_headers, value)) for value in _values]139 def days_rest(self):140 _headers = self._pull.json()['resultSets'][6]['headers']141 _values = self._pull.json()['resultSets'][6]['rowSet']142 return [dict(zip(_headers, value)) for value in _values]143class game_logs:144 def __init__(self, playerid, season='2015',seasontype=1, league='NBA'):145 self._url = "http://stats.nba.com/stats/playergamelog?"146 self._api_param = {'PlayerID':playerid,147 'SeasonType': _SeasonType(seasontype),148 'Season': _nbaSeason(season),149 }150 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)151 def logs(self):152 _headers = self._pull.json()['resultSets'][0]['headers']153 _values = self._pull.json()['resultSets'][0]['rowSet']154 return [dict(zip(_headers, value)) for value in _values]155class shot_dashboard:156 def __init__(self,playerid,league='NBA',season='2015', seasontype=1,teamid=0,157 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',158 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,159 period=0,lastngames=0, permode=1):160 self._url = "http://stats.nba.com/stats/playerdashptshots?"161 self._api_param = {'PlayerID' : playerid,162 'LeagueID': _nbaLeague(league),163 'Season' : _nbaSeason(season),164 'SeasonType' : _SeasonType(seasontype),165 'TeamID' : teamid,166 'Outcome' : _Outcome(outcome),167 'Location' : _Location(location),168 'Month' : month,169 'SeasonSegment' : _SeasonSegment(seasonsegment),170 'DateFrom' : _valiDate(datefrom),171 'DateTo' : _valiDate(dateto),172 'OpponentTeamID' : opponentteamid,173 'VsConference' : _VsConference(vsconf),174 'VsDivision' : _VsDivision(vsdiv),175 'GameSegment' : _GameSegment(gamesegment),176 'Period' : period,177 'LastNGames' : lastngames,178 'PerMode' : _PerModeMini(permode)179 }180 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)181 def overall(self):182 _headers = self._pull.json()['resultSets'][0]['headers']183 _values = self._pull.json()['resultSets'][0]['rowSet']184 return [dict(zip(_headers, value)) for value in _values]185 def general(self):186 _headers = self._pull.json()['resultSets'][1]['headers']187 _values = self._pull.json()['resultSets'][1]['rowSet']188 return [dict(zip(_headers, value)) for value in _values]189 def shot_clock(self):190 _headers = self._pull.json()['resultSets'][2]['headers']191 _values = self._pull.json()['resultSets'][2]['rowSet']192 return [dict(zip(_headers, value)) for value in _values]193 def dribble(self):194 _headers = self._pull.json()['resultSets'][3]['headers']195 _values = self._pull.json()['resultSets'][3]['rowSet']196 return [dict(zip(_headers, value)) for value in _values]197 def closest_defender(self):198 _headers = self._pull.json()['resultSets'][4]['headers']199 _values = self._pull.json()['resultSets'][4]['rowSet']200 return [dict(zip(_headers, value)) for value in _values]201 def closest_defender_10ft(self):202 _headers = self._pull.json()['resultSets'][5]['headers']203 _values = self._pull.json()['resultSets'][5]['rowSet']204 return [dict(zip(_headers, value)) for value in _values]205 def touch_time(self):206 _headers = self._pull.json()['resultSets'][6]['headers']207 _values = self._pull.json()['resultSets'][6]['rowSet']208 return [dict(zip(_headers, value)) for value in _values]209class rebound_dashboard:210 def __init__(self,playerid,league='NBA',season='2015', seasontype=1,teamid=0,211 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',212 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,213 period=0,lastngames=0,permode=1):214 self._url = "http://stats.nba.com/stats/playerdashptreb?"215 self._api_param = {'PlayerID' : playerid,216 'LeagueID': _nbaLeague(league),217 'Season' : _nbaSeason(season),218 'SeasonType' : _SeasonType(seasontype),219 'TeamID' : teamid,220 'Outcome' : _Outcome(outcome),221 'Location' : _Location(location),222 'Month' : month,223 'SeasonSegment' : _SeasonSegment(seasonsegment),224 'DateFrom' : _valiDate(datefrom),225 'DateTo' : _valiDate(dateto),226 'OpponentTeamID' : opponentteamid,227 'VsConference' : _VsConference(vsconf),228 'VsDivision' : _VsDivision(vsdiv),229 'GameSegment' : _GameSegment(gamesegment),230 'Period' : period,231 'LastNGames' : lastngames,232 'PerMode' : _PerModeMini(permode)233 }234 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)235 def overall(self):236 _headers = self._pull.json()['resultSets'][0]['headers']237 _values = self._pull.json()['resultSets'][0]['rowSet']238 return [dict(zip(_headers, value)) for value in _values]239 def shot_type(self):240 _headers = self._pull.json()['resultSets'][1]['headers']241 _values = self._pull.json()['resultSets'][1]['rowSet']242 return [dict(zip(_headers, value)) for value in _values]243 def contesting_rebounders(self):244 _headers = self._pull.json()['resultSets'][2]['headers']245 _values = self._pull.json()['resultSets'][2]['rowSet']246 return [dict(zip(_headers, value)) for value in _values]247 def shot_distance(self):248 _headers = self._pull.json()['resultSets'][3]['headers']249 _values = self._pull.json()['resultSets'][3]['rowSet']250 return [dict(zip(_headers, value)) for value in _values]251 def rebound_distance(self):252 _headers = self._pull.json()['resultSets'][4]['headers']253 _values = self._pull.json()['resultSets'][4]['rowSet']254 return [dict(zip(_headers, value)) for value in _values]255class passing_dashboard:256 def __init__(self,playerid,league='NBA',season='2015', seasontype=1,teamid=0,257 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',258 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,259 period=0,lastngames=0,permode=1):260 self._url = "http://stats.nba.com/stats/playerdashptpass?"261 self._api_param = {'PlayerID' : playerid,262 'LeagueID': _nbaLeague(league),263 'Season' : _nbaSeason(season),264 'SeasonType' : _SeasonType(seasontype),265 'TeamID' : teamid,266 'Outcome' : _Outcome(outcome),267 'Location' : _Location(location),268 'Month' : month,269 'SeasonSegment' : _SeasonSegment(seasonsegment),270 'DateFrom' : _valiDate(datefrom),271 'DateTo' : _valiDate(dateto),272 'OpponentTeamID' : opponentteamid,273 'VsConference' : _VsConference(vsconf),274 'VsDivision' : _VsDivision(vsdiv),275 'GameSegment' : _GameSegment(gamesegment),276 'Period' : period,277 'LastNGames' : lastngames,278 'PerMode' : _PerModeMini(permode)279 }280 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)281 def passes_made(self):282 _headers = self._pull.json()['resultSets'][0]['headers']283 _values = self._pull.json()['resultSets'][0]['rowSet']284 return [dict(zip(_headers, value)) for value in _values]285 def passes_received(self):286 _headers = self._pull.json()['resultSets'][1]['headers']287 _values = self._pull.json()['resultSets'][1]['rowSet']288 return [dict(zip(_headers, value)) for value in _values]289class defense_dashboard:290 def __init__(self,playerid,league='NBA',season='2015', seasontype=1,teamid=0,291 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',292 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,293 period=0,lastngames=0,permode=1):294 self._url = "http://stats.nba.com/stats/playerdashptreb?"295 self._api_param = {'PlayerID' : playerid,296 'LeagueID': _nbaLeague(league),297 'Season' : _nbaSeason(season),298 'SeasonType' : _SeasonType(seasontype),299 'TeamID' : teamid,300 'Outcome' : _Outcome(outcome),301 'Location' : _Location(location),302 'Month' : month,303 'SeasonSegment' : _SeasonSegment(seasonsegment),304 'DateFrom' : _valiDate(datefrom),305 'DateTo' : _valiDate(dateto),306 'OpponentTeamID' : opponentteamid,307 'VsConference' : _VsConference(vsconf),308 'VsDivision' : _VsDivision(vsdiv),309 'GameSegment' : _GameSegment(gamesegment),310 'Period' : period,311 'LastNGames' : lastngames,312 'PerMode' : _PerModeMini(permode)313 }314 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)315 def defending_shot(self):316 _headers = self._pull.json()['resultSets'][0]['headers']317 _values = self._pull.json()['resultSets'][0]['rowSet']318 return [dict(zip(_headers, value)) for value in _values]319class shot_log:320 def __init__(self,playerid,league='NBA',season='2015',seasontype=1,teamid=0,321 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',322 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,323 period=0,lastngames=0):324 self._url = "http://stats.nba.com/stats/playerdashptshotlog?"325 self._api_param = {'PlayerID' : playerid,326 'LeagueID': _nbaLeague(league),327 'Season' : _nbaSeason(season),328 'SeasonType' : _SeasonType(seasontype),329 'TeamID' : teamid,330 'Outcome' : _Outcome(outcome),331 'Location' : _Location(location),332 'Month' : month,333 'SeasonSegment' : _SeasonSegment(seasonsegment),334 'DateFrom' : _valiDate(datefrom),335 'DateTo' : _valiDate(dateto),336 'OpponentTeamID' : opponentteamid,337 'VsConference' : _VsConference(vsconf),338 'VsDivision' : _VsDivision(vsdiv),339 'GameSegment' : _GameSegment(gamesegment),340 'Period' : period,341 'LastNGames' : lastngames342 }343 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)344 def log(self):345 _headers = self._pull.json()['resultSets'][0]['headers']346 _values = self._pull.json()['resultSets'][0]['rowSet']347 return [dict(zip(_headers, value)) for value in _values]348class rebound_log:349 def __init__(self,playerid,league='NBA',season='2015',seasontype=1,teamid=0,350 outcome=1,location=1,month=0,seasonsegment=1,datefrom='',351 dateto='',opponentteamid=0,vsconf=1,vsdiv=1,gamesegment=1,352 period=0,lastngames=0):353 self._url = "http://stats.nba.com/stats/playerdashptreboundlogs?"354 self._api_param = {'PlayerID' : playerid,355 'LeagueID': _nbaLeague(league),356 'Season' : _nbaSeason(season),357 'SeasonType' : _SeasonType(seasontype),358 'TeamID' : teamid,359 'Outcome' : _Outcome(outcome),360 'Location' : _Location(location),361 'Month' : month,362 'SeasonSegment' : _SeasonSegment(seasonsegment),363 'DateFrom' : _valiDate(datefrom),364 'DateTo' : _valiDate(dateto),365 'OpponentTeamID' : opponentteamid,366 'VsConference' : _VsConference(vsconf),367 'VsDivision' : _VsDivision(vsdiv),368 'GameSegment' : _GameSegment(gamesegment),369 'Period' : period,370 'LastNGames' : lastngames371 }372 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)373 def log(self):374 _headers = self._pull.json()['resultSets'][0]['headers']375 _values = self._pull.json()['resultSets'][0]['rowSet']376 return [dict(zip(_headers, value)) for value in _values]377class shot_chart:378 def __init__(self,playerid,leagueid='',season='2015', seasontype=1,teamid=0,379 gameid='',outcome=1,location=1,month=0,seasonsegment=1,380 datefrom='',dateto='',opponentteamid=0,vsconf=1,vsdiv=1,381 position=1,period=0,lastngames=0,aheadbehind=1,382 contextmeasure=1,clutchtime=7,rookieyear='',383 contextfilter='',startperiod='1',endperiod='10',startrange='0',384 endrange='28800', gamesegment=1, rangetype='2'):385 if not rookieyear == '':386 rookieyear = _nbaSeason(rookieyear)387 self._url = "http://stats.nba.com/stats/shotchartdetail?"388 self._api_param = {'LeagueID': leagueid,389 'Season' : _nbaSeason(season),390 'SeasonType' : _SeasonType(seasontype),391 'TeamID' : teamid,392 'PlayerID' : playerid,393 'GameID' : gameid,394 'Outcome' : _Outcome(outcome),395 'Location' : _Location(location),396 'Month' : month,397 'SeasonSegment' : _SeasonSegment(seasonsegment),398 'DateFrom' : _valiDate(datefrom),399 'DateTo' : _valiDate(dateto),400 'OpponentTeamID' : opponentteamid,401 'VsConference' : _VsConference(vsconf),402 'VsDivision' : _VsDivision(vsdiv),403 'Position' : _Position(position),404 'GameSegment' : _GameSegment(gamesegment),405 'Period' : period,406 'LastNGames' : lastngames,407 'AheadBehind' : _AheadBehind(aheadbehind),408 'ContextMeasure' : _ContextMeasure(contextmeasure),409 'ClutchTime' : _ClutchTime(clutchtime),410 'RookieYear' : rookieyear,411 'ContextFilter':contextfilter,412 'StartPeriod':startperiod,413 'EndPeriod':endperiod,414 'StartRange':startrange,415 'EndRange':endrange,416 'RangeType':rangetype,417 }418 self._pull = _requests.get(self._url, params=self._api_param, headers=my_headers)419 def chart(self):420 _headers = self._pull.json()['resultSets'][0]['headers']421 _values = self._pull.json()['resultSets'][0]['rowSet']422 return [dict(zip(_headers, value)) for value in _values]423 def leagueaverage(self):424 _headers = self._pull.json()['resultSets'][1]['headers']425 _values = self._pull.json()['resultSets'][1]['rowSet']426 return [dict(zip(_headers, value)) for value in _values]427def PlayerList(season='2015', AllTime=False, league='NBA'):428 if AllTime:429 _url = "http://stats.nba.com/stats/commonallplayers?"430 _api_param = {'IsOnlyCurrentSeason':"0",431 'LeagueID':_nbaLeague(league),432 'Season': "2015-16"}433 _pull = _requests.get(_url, params=_api_param, headers=my_headers)434 _headers = _pull.json()['resultSets'][0]['headers']435 _values = _pull.json()['resultSets'][0]['rowSet']436 return [dict(zip(_headers, value)) for value in _values]437 else:438 _url = "http://stats.nba.com/stats/commonallplayers?"439 _api_param = {'IsOnlyCurrentSeason':"0",440 'LeagueID': _nbaLeague(league),441 'Season': _nbaSeason(season)}442 _pull = _requests.get(_url, params=_api_param, headers=my_headers)443 _headers = _pull.json()['resultSets'][0]['headers']444 _values = _pull.json()['resultSets'][0]['rowSet']445 return [dict(zip(_headers, value)) for value in _values]446__all__ = ["demographics", "career_stats", "general_splits",447 "game_logs", "shot_dashboard", "rebound_dashboard",448 "passing_dashboard", "defense_dashboard", "shot_log",...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!