def test_get_top_games_raises_attribute_exception_for_invalid_params(): responses.add(responses.GET, '{}games/top'.format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type='application/json') client = TwitchHelix('client id') kwargs = {'page_size': 101} with pytest.raises(TwitchAttributeException): client.get_top_games(**kwargs) assert len(responses.calls) == 0
def test_get_top_games_passes_all_params_to_request(): responses.add( responses.GET, "{}games/top".format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") games = client.get_top_games( after="eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ==", before="eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0Ijo0MH19==", page_size=100, ) game = games.next() assert len(responses.calls) == 1 assert isinstance(games, APICursor) assert isinstance(game, Game) url = responses.calls[0].request.url assert url.startswith("https://api.twitch.tv/helix/games/top?") assert "after=eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ%3D%3D" in url assert "before=eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0Ijo0MH19%3D%3D" in url assert "first=100" in url
def test_get_top_games_returns_api_cursor(): responses.add(responses.GET, '{}games/top'.format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type='application/json') client = TwitchHelix('client id') games = client.get_top_games() assert len(responses.calls) == 1 assert isinstance(games, APICursor)
def test_get_top_games_next_returns_game_object(): responses.add(responses.GET, '{}games/top'.format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type='application/json') client = TwitchHelix('client id') games = client.get_top_games() game = games.next() assert len(responses.calls) == 1 assert isinstance(games, APICursor) assert games._cursor == example_get_top_games_response['pagination']['cursor'] assert isinstance(game, Game) assert game.id == example_get_top_games_response['data'][0]['id'] assert game.name == example_get_top_games_response['data'][0]['name']
def test_get_top_games_next_returns_game_object(): responses.add( responses.GET, "{}games/top".format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") games = client.get_top_games() game = games.next() assert len(responses.calls) == 1 assert isinstance(games, APICursor) assert games._cursor == example_get_top_games_response["pagination"]["cursor"] assert isinstance(game, Game) assert game.id == example_get_top_games_response["data"][0]["id"] assert game.name == example_get_top_games_response["data"][0]["name"]
for stream in islice(streams_iterator, 0, 5): print(stream) client = TwitchClient(client_id='x2nlpgpmb4nn6m1o1vby49mif3qeqy') users = client.users.translate_usernames_to_ids(['vektv', 'jukes','officialf0xey']) for user in users: print('{}: {}'.format(user.name, user.id)) client = TwitchHelix(client_id='x2nlpgpmb4nn6m1o1vby49mif3qeqy') streams_iterator = client.get_streams_metadata(page_size=100,user_ids=[77208443]) for stream in islice(streams_iterator, 0, 5): print(stream) client = TwitchHelix(client_id='x2nlpgpmb4nn6m1o1vby49mif3qeqy') games_iterator = client.get_top_games(page_size=100) for game in islice(games_iterator, 0, 10): print(game) print("\n") client = TwitchHelix(client_id='x2nlpgpmb4nn6m1o1vby49mif3qeqy') #games_iterator = client.get_games(game_ids=['509658'])#names=['Counter-Strike: Global Offensive']) games_iterator = client.get_games(names=["Counter-Strike: Global Offensive","FIFA 19","NHL 19"]) for game in islice(games_iterator, 0, 10): print(game) from twitch import TwitchClient client = TwitchClient('x2nlpgpmb4nn6m1o1vby49mif3qeqy') teams = client.teams.get_all() for t in islice(teams, 0, 10): print(t)
def top_games(): client = TwitchHelix() games_iterator = client.get_top_games(page_size=3) for game in islice(games_iterator, 0, 6): print(game)