From 25bc398ec1e13cd03f2806be1668faa70161cc74 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Fri, 11 Mar 2022 17:28:50 +0100 Subject: [PATCH] More URLs cleanup --- constants.py | 5 +---- twitch.py | 15 +++++++++------ websocket.py | 8 +++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/constants.py b/constants.py index 36d1987..390bfea 100644 --- a/constants.py +++ b/constants.py @@ -20,11 +20,8 @@ TopicProcess: TypeAlias = "abc.Callable[[int, JsonType], Any]" # Values MAX_WEBSOCKETS = 8 WS_TOPICS_LIMIT = 50 -# URLs +# Misc BASE_URL = "https://twitch.tv" -WEBSOCKET_URL = "wss://pubsub-edge.twitch.tv/v1" -GQL_URL = "https://gql.twitch.tv/gql" -# Misc for Twitch CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko" USER_AGENT = ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " diff --git a/twitch.py b/twitch.py index 9abcba3..4113a76 100644 --- a/twitch.py +++ b/twitch.py @@ -23,7 +23,6 @@ from inventory import DropsCampaign from utils import task_wrapper, timestamp, AwaitableValue, OrderedSet from exceptions import RequestException, LoginException, CaptchaRequired from constants import ( - GQL_URL, BASE_URL, CLIENT_ID, USER_AGENT, @@ -824,12 +823,16 @@ class Twitch: ) from cause async def gql_request(self, op: GQLOperation) -> JsonType: - headers = { - "Authorization": f"OAuth {self._access_token}", - "Client-Id": CLIENT_ID, - } gql_logger.debug(f"GQL Request: {op}") - async with self.request("POST", GQL_URL, json=op, headers=headers) as response: + async with self.request( + "POST", + "https://gql.twitch.tv/gql", + json=op, + headers={ + "Authorization": f"OAuth {self._access_token}", + "Client-Id": CLIENT_ID, + } + ) as response: response_json: JsonType = await response.json() gql_logger.debug(f"GQL Response: {response_json}") return response_json diff --git a/websocket.py b/websocket.py index 6d24660..608a400 100644 --- a/websocket.py +++ b/websocket.py @@ -15,7 +15,7 @@ except ModuleNotFoundError as exc: from exceptions import MinerException from utils import task_wrapper, create_nonce, AwaitableValue -from constants import WEBSOCKET_URL, PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT +from constants import PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT if TYPE_CHECKING: from twitch import Twitch @@ -110,10 +110,12 @@ class Websocket: async def _handle(self): # ensure we're logged in before connecting await self._twitch.wait_until_login() - self.set_status("Connecting...") ws_logger.info(f"Websocket[{self._idx}] connecting...") + self.set_status("Connecting...") # Connect/Reconnect loop - async for websocket in websocket_connect(WEBSOCKET_URL, ssl=True, ping_interval=None): + async for websocket in websocket_connect( + "wss://pubsub-edge.twitch.tv/v1", ssl=True, ping_interval=None + ): # 3 minutes of max backoff websocket.BACKOFF_MAX = 3 * 60 # type: ignore self._ws.set(websocket)