Ejemplo n.º 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
Ejemplo n.º 2
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))
Ejemplo n.º 3
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)
    )
Ejemplo n.º 4
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