def test_get_user_follows_raises_attribute_exception_if_no_param_is_set(): responses.add(responses.GET, '{}users/follows'.format(BASE_HELIX_URL), body=json.dumps(example_get_clips_response), status=200, content_type='application/json') client = TwitchHelix('client id') with pytest.raises(TwitchAttributeException): client.get_user_follows() assert len(responses.calls) == 0
def test_get_user_follows_raises_attribute_exception_for_invalid_params(): responses.add(responses.GET, '{}users/follows'.format(BASE_HELIX_URL), body=json.dumps(example_get_top_games_response), status=200, content_type='application/json') client = TwitchHelix('client id') kwargs = {'from_id': 23161357, 'page_size': 101} with pytest.raises(TwitchAttributeException): client.get_user_follows(**kwargs) assert len(responses.calls) == 0
def test_get_user_follows_passes_all_params_to_request(): responses.add( responses.GET, "{}users/follows".format(BASE_HELIX_URL), body=json.dumps(example_get_streams_metadata_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") user_follows = client.get_user_follows( after="eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ==", page_size=100, from_id=23161357, to_id=12345678, ) follow = user_follows.next() assert len(responses.calls) == 1 assert isinstance(user_follows, APICursor) assert isinstance(follow, Follow) url = responses.calls[0].request.url assert url.startswith("https://api.twitch.tv/helix/users/follows?") assert "after=eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ%3D%3D" in url assert "first=100" in url assert "from_id=23161357" in url assert "to_id=12345678" in url
def test_get_user_follows_next_returns_follow_object(): responses.add( responses.GET, "{}users/follows".format(BASE_HELIX_URL), body=json.dumps(example_get_user_follows_response), status=200, content_type="application/json", ) client = TwitchHelix("client id") user_follows = client.get_user_follows(to_id=23161357) follow = user_follows.next() assert len(responses.calls) == 1 assert isinstance(user_follows, APICursor) assert ( user_follows.cursor == example_get_user_follows_response["pagination"]["cursor"] ) assert user_follows.total == example_get_user_follows_response["total"] assert isinstance(follow, Follow) assert follow.from_id == example_get_user_follows_response["data"][0]["from_id"] assert follow.to_id == example_get_user_follows_response["data"][0]["to_id"] assert follow.followed_at == datetime(2017, 8, 22, 22, 55, 24)
def test_get_user_follows_returns_api_cursor(): responses.add(responses.GET, '{}users/follows'.format(BASE_HELIX_URL), body=json.dumps(example_get_user_follows_response), status=200, content_type='application/json') client = TwitchHelix('client id') user_follows = client.get_user_follows(to_id=23161357) assert len(responses.calls) == 1 assert isinstance(user_follows, APICursor)
def canales_de_cliente(username): helix = TwitchHelix(client_id='vnsbdjciw4fcif1k57w1c07a65wk03', oauth_token='oauth:17qyf4koyvfdqjs4me7zr451lccmtn') HEADS = { "Accept": "application/vnd.twitchtv.v5+json", "Client-ID": "vnsbdjciw4fcif1k57w1c07a65wk03" #"Authorization" : "OAuth 17qyf4koyvfdqjs4me7zr451lccmtn" } nombre = username URL = "https://api.twitch.tv/kraken/users?login={}".format(nombre) r = requests.get(url=URL, headers=HEADS) temp = r.json() id = temp["users"][0]["_id"] namefollows = [] t = helix.get_user_follows(from_id=id) namefollows = [] for i in t: namefollows.append(i["to_name"]) #print(namefollows) return namefollows
def test_get_user_follows_next_returns_follow_object(): responses.add(responses.GET, '{}users/follows'.format(BASE_HELIX_URL), body=json.dumps(example_get_user_follows_response), status=200, content_type='application/json') client = TwitchHelix('client id') user_follows = client.get_user_follows(to_id=23161357) follow = user_follows.next() assert len(responses.calls) == 1 assert isinstance(user_follows, APICursor) assert user_follows.cursor == example_get_user_follows_response['pagination']['cursor'] assert user_follows.total == example_get_user_follows_response['total'] assert isinstance(follow, Follow) assert follow.from_id == example_get_user_follows_response['data'][0]['from_id'] assert follow.to_id == example_get_user_follows_response['data'][0]['to_id'] assert follow.followed_at == datetime(2017, 8, 22, 22, 55, 24)
class apiTwitch(AbstactClassApi): def __init__(self, *args): super().__init__(*args) self.helix = TwitchHelix( client_id='vnsbdjciw4fcif1k57w1c07a65wk03', oauth_token='oauth:17qyf4koyvfdqjs4me7zr451lccmtn') self.client = TwitchClient( client_id='vnsbdjciw4fcif1k57w1c07a65wk03', oauth_token='oauth:17qyf4koyvfdqjs4me7zr451lccmtn') def get_userid(self, username): nombre = username URL = "https://api.twitch.tv/kraken/users?login={}".format(nombre) r = requests.get(url=URL, headers=self.HEADS) temp = r.json() id_usuario = temp["users"][0]["_id"] ############################################################# return id_usuario def get_followers(self, id_cliente): namefollows = [] t = self.helix.get_user_follows(from_id=id_cliente) namefollows = [] for i in t: namefollows.append(i["to_id"]) #print(namefollows) return namefollows def get_name(self, id_streamer): self.id_streamer = id_streamer channel = self.client.channels.get_by_id(self.id_streamer) nombre_streamer = channel.name return nombre_streamer def get_followe(self, id_streamer): seguidoresStreamer = self.client.channels.get_by_id(id_streamer) cantidad = seguidoresStreamer["followers"] return cantidad
import requests import twitch from twitch import TwitchHelix, TwitchClient client = TwitchHelix(client_id= 'vnsbdjciw4fcif1k57w1c07a65wk03', oauth_token= 'oauth:17qyf4koyvfdqjs4me7zr451lccmtn') HEADS = { "Accept" : "application/vnd.twitchtv.v5+json", "Client-ID" : "vnsbdjciw4fcif1k57w1c07a65wk03" #"Authorization" : "OAuth 17qyf4koyvfdqjs4me7zr451lccmtn" } nombre = "pokimane" URL = "https://api.twitch.tv/kraken/users?login={}".format(nombre) r = requests.get(url = URL, headers = HEADS) temp = r.json() try: id = temp["users"][0]["_id"] print(id) t = client.get_user_follows(from_id = id) for i in t: print(i["to_name"]) except: print("Some error occured") #print(client.get_user_follows(from_id = "118237854")) #print(client.get)
def user_follows(): client = TwitchHelix() user_follows_iterator = client.get_user_follows(to_id=23161357) print('Total: {}'.format(user_follows_iterator.total)) for user_follow in islice(user_follows_iterator, 0, 10): print(user_follow)