def find_summary(game_id): # 0041400161 summary = 'http://stats.nba.com/stats/boxscoresummaryv2?GameID=' \ + str(game_id) summary_resp = requests.get(summary) if summary_resp.status_code >= 400: print('no such game ' + str(summary_resp.status_code)) return False try: home_team_id = summary_resp.json()['resultSets'][0]['rowSet'][0][6] line_score = summary_resp.json()['resultSets'][5] line_score['headers'].append('IS_HOME') is_home = (line_score['rowSet'][0][3] == home_team_id) line_score['rowSet'][0].append(is_home) line_score['rowSet'][1].append(not is_home) # CsvHelper.list2d_to_csv( # dict_to_list2d(game_summary), 'summary_' + str(game_id) # ) CsvHelper.list2d_to_csv( dict_to_list2d(line_score), PATH + 'line_score_' + str(game_id) ) except (KeyError, IndexError, TypeError, ValueError): print(summary) return True
def find_every_player_hot(): stats = find_all_players(1) l2d = dict_to_list2d(stats)[1:] i = 0 for l in l2d: print(i) names = l[1].lower().split(',') # assert len(names) == 2 find_hot(names[1].strip() + UNDER + names[0].strip()) i += 1
def team_profile(team_id, season='2014-15'): url = 'http://stats.nba.com/stats/teaminfocommon?LeagueID=00&SeasonType=Regular+Season&TeamID=' \ + str(team_id) + \ '&season=' \ + str(season) response = requests.get(url) if not valid_response(response): return stats = response.json()['resultSets'][0] list2d_to_csv(dict_to_list2d(stats), PATH + 'team_profile_' + str(team_id) + UNDER + season)
def player_profile(player_id, season=SeasonType.regular): url = 'http://stats.nba.com/stats/commonplayerinfo?LeagueID=00&PlayerID=' \ + str(player_id) + \ '&SeasonType=' \ + season.value response = requests.get(url) if not valid_response(response): return stats = response.json()['resultSets'][0] CsvHelper.list2d_to_csv(dict_to_list2d(stats), 'player_profile_' + str(player_id))
def find_detail(season, game_id, detail_type): # http://stats.nba.com/stats/boxscoreadvancedv2?EndPeriod=10&EndRange=28800&GameID= # 0020000654 # &RangeType=2&Season= # 2000-01 # &SeasonType=Regular+Season&StartPeriod=1&StartRange=0 # '2014-15', 0021400160 detail = 'http://stats.nba.com/stats/boxscore' \ + str(detail_type.name) + \ 'v2?EndPeriod=10&EndRange=28800&' \ 'GameID=' \ + str(game_id) + \ '&RangeType=2&Season=' \ + str(season) + \ '&SeasonType=Regular+Season&StartPeriod=1&StartRange=0' detail_resp = requests.get(detail) if detail_resp.status_code >= 400: print('no such game ' + str(detail_resp.status_code)) return False try: player_stats = detail_resp.json()['resultSets'][0] team_stats = detail_resp.json()['resultSets'][1] from hw_scrape import CsvHelper CsvHelper.list2d_to_csv( dict_to_list2d(player_stats), PATH + 'player_' + str(game_id) + UNDER + str(detail_type.name) ) CsvHelper.list2d_to_csv( dict_to_list2d(team_stats), PATH + 'team_' + str(game_id) + UNDER + str(detail_type.name) ) except (KeyError, IndexError, TypeError): print(detail) return True
def player_profile(player_id, season=SeasonType.regular): url = 'http://stats.nba.com/stats/commonplayerinfo?LeagueID=00&PlayerID=' \ + str(player_id) + \ '&SeasonType=' \ + season.value response = requests.get(url) if not valid_response(response): return stats = response.json()['resultSets'][0] CsvHelper.list2d_to_csv( dict_to_list2d(stats), 'player_profile_' + str(player_id) )
def team_profile(team_id, season='2014-15'): url = 'http://stats.nba.com/stats/teaminfocommon?LeagueID=00&SeasonType=Regular+Season&TeamID=' \ + str(team_id) + \ '&season=' \ + str(season) response = requests.get(url) if not valid_response(response): return stats = response.json()['resultSets'][0] list2d_to_csv( dict_to_list2d(stats), PATH + 'team_profile_' + str(team_id) + UNDER + season )
def get_overall_pie(season): stats = find_all_players() l2d = dict_to_list2d(stats)[1:] starter = [] bench = [] for l in l2d: pie = get_pie(l[0], season, ptype=PIEType.overall) if pie[0] == STARTER: starter.append(pie[1]) elif pie[0] == BENCH: bench.append(pie[1]) # list2d_to_csv(starter, 'starter_pie') # list2d_to_csv(bench, 'bench_pie') return [starter, bench]
def find_player(player_id, player_data_type, season_type=ParameterType.SeasonType.regular): url = ( "http://stats.nba.com/stats/playerdashboardbygeneralsplits?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=" + player_data_type.name + "&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=" + str(player_id) + "&PlusMinus=N&Rank=N&Season=2014-15&SeasonSegment=&SeasonType=" + season_type.value + "&VsConference=&VsDivision=" ) response = requests.get(url) if response.status_code > 400: print("no such player") return overall = response.json()["resultSets"][0] list2d_to_csv(dict_to_list2d(overall), "player_" + str(player_id) + "_" + player_data_type.name)
def find_player(player_id, player_data_type, season_type=ParameterType.SeasonType.regular): url = 'http://stats.nba.com/stats/playerdashboardbygeneralsplits?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=' \ + player_data_type.name + \ '&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=' \ + str(player_id) + \ '&PlusMinus=N&Rank=N&Season=2014-15&SeasonSegment=&SeasonType=' \ + season_type.value + \ '&VsConference=&VsDivision=' response = requests.get(url) if response.status_code > 400: print('no such player') return overall = response.json()['resultSets'][0] list2d_to_csv(dict_to_list2d(overall), 'player_' + str(player_id) + '_' + player_data_type.name)
def find_every_player(): stats = find_all_players(1) l2d = dict_to_list2d(stats)[1:] for l in l2d: player_profile(l[0])
def find_every_player(): stats = find_all_players(1) l2d = dict_to_list2d(stats)[1:] for l in l2d: find_player(l[0], PlayerType.Base)
def find_every_team(season='2013-14'): stats = find_all_teams() l2d = dict_to_list2d(stats)[1:] for l in l2d: team_profile(l[0], season)