示例#1
0
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
示例#2
0
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
示例#3
0
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
示例#4
0
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)
示例#5
0
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))
示例#6
0
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
示例#7
0
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)
    )
示例#8
0
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
    )
示例#9
0
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]
示例#10
0
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)
示例#11
0
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)
示例#12
0
def find_every_player():
    stats = find_all_players(1)
    l2d = dict_to_list2d(stats)[1:]
    for l in l2d:
        player_profile(l[0])
示例#13
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)
示例#14
0
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)
示例#15
0
def find_every_player():
    stats = find_all_players(1)
    l2d = dict_to_list2d(stats)[1:]
    for l in l2d:
        player_profile(l[0])
示例#16
0
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)
示例#17
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)