Beispiel #1
0
def find_live(game_id, period):
    # http://china.nba.com/wap/static/data/game/playbyplay_0041400311_4.json
    aim = 'http://china.nba.com/wap/static/data/game/playbyplay_' \
          + str(game_id) + \
          '_' \
          + str(period) + \
          '.json'

    game = requests.get(aim)
    game.encoding = 'utf-8'
    if game.status_code >= 400:
        print('no suck game ' + str(game.status_code))
        return False
    try:
        events = game.json()['payload']['playByPlays'][0]['events']
        file_id = PATH + 'live' + str(game_id) + '_' + str(period)

        # CsvHelper.dict_to_csv_stream(events[0])
        # for x in range(1, len(events)):
        #     CsvHelper.dict_to_csv_stream(
        #         events[x], False
        #     )
        CsvHelper.dict_to_csv(events[0], file_id)
        for x in range(1, len(events)):
            CsvHelper.dict_to_csv(
                events[x], file_id, False, mode='a'
            )

    except (ValueError, IndexError):
        print(aim)

    return True
Beispiel #2
0
def find_live(game_id, period):
    # http://china.nba.com/wap/static/data/game/playbyplay_0041400311_4.json
    aim = 'http://china.nba.com/wap/static/data/game/playbyplay_' \
          + str(game_id) + \
          '_' \
          + str(period) + \
          '.json'

    game = requests.get(aim)
    game.encoding = 'utf-8'
    if game.status_code >= 400:
        print('no suck game ' + str(game.status_code))
        return False
    try:
        events = game.json()['payload']['playByPlays'][0]['events']
        file_id = PATH + 'live' + str(game_id) + '_' + str(period)

        # CsvHelper.dict_to_csv_stream(events[0])
        # for x in range(1, len(events)):
        #     CsvHelper.dict_to_csv_stream(
        #         events[x], False
        #     )
        CsvHelper.dict_to_csv(events[0], file_id)
        for x in range(1, len(events)):
            CsvHelper.dict_to_csv(events[x], file_id, False, mode='a')

    except (ValueError, IndexError):
        print(aim)

    return True