def get_roster(team_obj, sesson): if sesson is None: sesson = Utils.make_season() elif not Utils.validate_date(sesson): Log.red('illegal date! pattern is yyyy-yy as 2017-18.') return teamid = team_obj['teamId'] Progress.mock_wait('load team roster:' + str(teamid)) h = dict(Constant.HEADERS) resp = requests.get(__ROSTER_API.format(TeamID=teamid, Season=sesson), params=None, headers=h, timeout=6) resp.raise_for_status() resp_json = resp.json() roster_arr = resp_json['resultSets'] Progress.mock_end() Display.display_team_roster(roster_arr, sesson)
def get_game_log(team_obj, season_type, sesson): if sesson is None: sesson = Utils.make_season() elif not Utils.validate_date(sesson): Log.red('illegal date! pattern is yyyy-yy as 2017-18.') return teamid = team_obj['teamId'] Progress.mock_wait('load team game log:' + str(teamid)) h = dict(Constant.HEADERS) resp = requests.get(__GAME_LOG_API.format(TeamID=teamid, Season=sesson, SeasonType=season_type), params=None, headers=h, timeout=6) resp.raise_for_status() resp_json = resp.json() game_arr = resp_json['resultSets'][0]['rowSet'] Progress.mock_end() Display.display_team_game_log(game_arr, sesson, season_type == "Playoffs")
def display_game_log(game_log_arr): if len(game_log_arr) == 0: Log.red("no record") return table = PrettyTable([ "DATE", "VS", "WIN", "MIN", "PTS", "REB", "AST", "OREB", "DREB", "FG_PCT", "FG3_PCT", "FT_PCT", "BLK", "STL", "TOV", "PF", "+-", "GAME_ID" ]) table.color_cols = {"GAME_ID": Log.wrap_yellow} for game_obj in game_log_arr: table.add_row([ game_obj[3], game_obj[4], game_obj[5], game_obj[6], game_obj[24], game_obj[18], game_obj[19], game_obj[16], game_obj[17], Utils.make_pct(game_obj, 7, False), Utils.make_pct(game_obj, 10, False), Utils.make_pct(game_obj, 13, False), game_obj[21], game_obj[20], game_obj[22], game_obj[23], game_obj[25], game_obj[2] ]) print table
def display_player_stat_all(obj, career, playoff=False): table = PrettyTable([ playoff is True and "PLAYOFF" or "SEASON", "TEAM", "GP", "MIN", "PTS", "FG_PCT", "FG3_PCT", "FT_PCT", "REB", "OREB", "DREB", "AST", "BLK", "STL", "TOV", "PF" ]) for season_obj in reversed(obj): table.add_row([ season_obj[1], season_obj[4], season_obj[6], season_obj[8], season_obj[26], Utils.make_pct(season_obj), Utils.make_pct(season_obj, 12), Utils.make_pct(season_obj, 15), season_obj[20], season_obj[18], season_obj[19], season_obj[21], season_obj[23], season_obj[22], season_obj[24], season_obj[25] ]) for season_obj in career: table.add_row([ "career", "", season_obj[3], season_obj[5], season_obj[23], Utils.make_pct(season_obj, 6), Utils.make_pct(season_obj, 9), Utils.make_pct(season_obj, 12), season_obj[15], season_obj[16], season_obj[17], season_obj[18], season_obj[19], season_obj[20], season_obj[21], season_obj[22] ]) print table
def display_team_game_log(game_arr, season, playoff): if len(game_arr) == 0: Log.red('no record') return table = PrettyTable([ playoff and "PLAYOFF" or "SEASON", "DATE", "MATCHUP", "WL", "PTS", "FG_PCT", "FG3_PCT", "FT_PCT", "REB", "OREB", "DREB", "AST", "BLK", "STL", "TOV", "PF", "GAME_ID" ]) table.color_cols = {'GAME_ID': Log.wrap_yellow} for game_obj in game_arr: table.add_row([ season, game_obj[2], game_obj[3], game_obj[4], game_obj[26], Utils.make_pct(game_obj, 9, point=False), Utils.make_pct(game_obj, point=False), Utils.make_pct(game_obj, 15, point=False), game_obj[20], game_obj[18], game_obj[19], game_obj[21], game_obj[23], game_obj[22], game_obj[24], game_obj[25], game_obj[1] ]) print table
def get_player_log(player_obj, m_date, season_type): pid = player_obj[0] if m_date is None: m_date = Utils.make_season() elif not Utils.validate_date(m_date): Log.red('illegal date! pattern is yyyy-yy as 2017-18.') return try: Progress.mock_wait('load player game log') h = dict(Constant.HEADERS) resp = requests.get( __GAME_LOG_API.format(PlayerId=pid, Season=m_date, SeasonType=season_type), params=None, headers=h, timeout=6) resp.raise_for_status() resp_json = resp.json() log_arr = resp_json['resultSets'][0]['rowSet'] Progress.mock_end() Display.display_game_log(log_arr) except Exception, e: Progress.mock_end() print e
def display_team_stat(stat_arr, season, playoff): season_stat_arr = stat_arr[1]['rowSet'] if len(season_stat_arr) == 0: Log.red('no record') return table = PrettyTable([ playoff and "PLAYOFF" or "SEASON", "PLAYER", "GP", "MIN", "PTS", "FG_PCT", "FG3_PCT", "FT_PCT", "REB", "OREB", "DREB", "AST", "BLK", "STL", "TOV", "PF", "+-" ]) season_stat_arr = sorted(season_stat_arr, __sort_team_stat) for stat_obj in season_stat_arr: table.add_row([ season, stat_obj[2], stat_obj[3], stat_obj[7], stat_obj[27], Utils.make_pct(stat_obj, 8), Utils.make_pct(stat_obj, 11), Utils.make_pct(stat_obj, 14), stat_obj[19], stat_obj[17], stat_obj[18], stat_obj[20], stat_obj[23], stat_obj[22], stat_obj[21], stat_obj[25], stat_obj[28] ]) print table
def get_player_stat_advanced(player_obj, playoff=False): pid = player_obj[0] try: Progress.mock_wait('load player advanced stat') h = dict(Constant.HEADERS) resp = requests.get(__STAT_ADVANCED_API.format(PlayerId=pid, Season=Utils.make_season(), SeasonType=( playoff and 'Playoffs' or 'Regular Season')), params=None, headers=h, timeout=5) resp.raise_for_status() Progress.mock_end() resp_json = resp.json() stat_arr = resp_json['resultSets'][1]['rowSet'] Display.display_player_advanced_stat(stat_arr, playoff) except Exception, e: Progress.mock_end() print e
def display_base_profile(obj): table = PrettyTable([ "FIRSTNAME", "LASTNAME", "TEAM", "POSITION", "HEIGHT", "WEIGHT", "BIRTHDAY", "JERSEY", "DRAFT", ]) table.align = "c" table.add_row([ obj[1], obj[2], obj[18], obj[14], obj[10], obj[11], obj[6][0:10], obj[13], Utils.make_draft(obj) ]) print table
def display_game_detail(sum_arr, box_arr): line_score = sum_arr[5]['rowSet'] if len(line_score) == 0: Log.red("no record") return index = 12 titles = ['', "Q1", "Q2", "Q3", "Q4"] while index < 22 and line_score[0][index] > 0: index = index + 1 titles.append("TO" + str(index - 12)) titles.extend( ['FINAL', 'PTS_PAINT', 'PTS_2ND_CHANCE', 'PTS_OFF_TO', 'LARGEST_LEAD']) table = PrettyTable(titles) temp_index = 0 crown_index = 0 if line_score[0][22] > line_score[1][22] else 1 for score_obj in line_score: other_score = sum_arr[1]['rowSet'][temp_index] row = [ str(score_obj[4]) + (temp_index == crown_index and '' or '0041700152'), score_obj[8], score_obj[9], score_obj[10], score_obj[11] ] for i in range(12, index): row.append(score_obj[i]) row.extend([ score_obj[22], other_score[4], other_score[5], other_score[13], other_score[7] ]) temp_index = temp_index + 1 table.add_row(row) print table table = PrettyTable( ['', '', '', '', '', "", "", "", "", "", "", "", "", "", ""]) table.header = False score_arr = box_arr[0]['rowSet'] temp_team = score_arr[0][2] temp_index = 0 for box_obj in score_arr: temp_index += 1 if box_obj[2] != temp_team: table.add_row([ 'PLAYER', 'MIN', 'PTS', "FG_PCT", "FG3_PCT", "FT_PCT", "REB", "OREB", "DREB", "AST", "BLK", "STL", "TOV", "PF", "+-" ]) table.mid_head_index = temp_index temp_team = box_obj[2] dnp = box_obj[8] is None if dnp: table.add_row([ box_obj[5], 'DNP', '', '', '', '', '', '', '', '', '', '', '', '', '' ]) else: table.add_row([ box_obj[5] + (len(box_obj[6]) > 0 and " (" + box_obj[6] + ")" or ""), box_obj[8], box_obj[26], Utils.make_pct(box_obj, 9, False), Utils.make_pct(box_obj, 12, False), Utils.make_pct(box_obj, 15, False), box_obj[20], box_obj[18], box_obj[19], box_obj[21], box_obj[23], box_obj[22], box_obj[24], box_obj[25], int(box_obj[27]) ]) print table