From 8b8386febdf3ed3479117d17fbdfabfe95730b2b Mon Sep 17 00:00:00 2001 From: gbtami Date: Sun, 29 Dec 2024 23:02:15 +0100 Subject: [PATCH] Fix testing twitch CALLBACK_URL --- server/twitch.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/server/twitch.py b/server/twitch.py index 2bc0cb3f4..0f01ee8cd 100644 --- a/server/twitch.py +++ b/server/twitch.py @@ -21,8 +21,7 @@ TWITCH_STREAMS_API_URL = "https://api.twitch.tv/helix/streams" if DEV: - # https://github.com/localtunnel/localtunnel - CALLBACK_URL = "https://fresh-husky-89.loca.lt/twitch" + CALLBACK_URL = "https://localhost" else: CALLBACK_URL = "https://www.pychess.org/twitch" @@ -76,13 +75,15 @@ async def init_subscriptions(self): await self.get_subscriptions() for subscription_id in self.subscriptions: + print("delete subs id", subscription_id) await self.delete_subscription(subscription_id) uids = await self.get_users_data(TWITCH_STREAMERS.keys()) - for uid in uids: - await self.request_subscription(uid, "stream.online") - await self.request_subscription(uid, "stream.offline") - await self.request_subscription(uid, "channel.update") + for name, uid in uids: + print("request subs", name, uid) + await self.request_subscription(name, uid, "stream.online") + await self.request_subscription(name, uid, "stream.offline") + await self.request_subscription(name, uid, "channel.update") if len(self.streams) > 0: await broadcast_streams(self.app) @@ -130,9 +131,10 @@ async def delete_subscription(self, subscription_id): ): pass - async def request_subscription(self, broadcaster_user_id, subscription_type): + async def request_subscription(self, name, broadcaster_user_id, subscription_type): log.debug( - "--- request_subscription ---- %s %s", + "--- request_subscription ---- %s %s %s", + name, broadcaster_user_id, subscription_type, ) @@ -166,7 +168,10 @@ async def get_subscriptions(self): async with aiohttp.ClientSession() as client_session: async with client_session.get(TWITCH_EVENTSUB_API_URL, headers=self.headers) as resp: response_data = await resp.json() + print("---response---") for subs in response_data["data"]: + print(subs) + print("---") self.subscriptions[subs["id"]] = subs async def get_users_data(self, usernames): @@ -174,7 +179,7 @@ async def get_users_data(self, usernames): async with aiohttp.ClientSession() as client_session: uids = [] query_params = "&".join(["login=%s" % username for username in usernames]) - + print("---USERS") async with client_session.get( "%s?%s" % (TWITCH_USERS_API_URL, query_params), headers=self.headers ) as resp: @@ -184,9 +189,11 @@ async def get_users_data(self, usernames): else: json = await resp.json() for user in json["data"]: - uids.append(user["id"]) + print(user["login"], user["id"]) + uids.append((user["login"], user["id"])) query_params = "&".join(["user_login=%s" % username for username in usernames]) + print("---STREAMS") async with client_session.get( "%s?%s" % (TWITCH_STREAMS_API_URL, query_params), headers=self.headers ) as resp: @@ -196,6 +203,7 @@ async def get_users_data(self, usernames): else: json = await resp.json() for stream in json["data"]: + print(stream) title = stream["title"] streamer = stream["user_login"] live = stream["type"] == "live"