mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-05-30 17:09:36 +00:00
remove redundant stuff
This commit is contained in:
@@ -63,16 +63,12 @@ class GQLClient:
|
||||
self._qgl_limiter = RateLimiter(capacity=5, window=1)
|
||||
|
||||
@overload
|
||||
async def request(self, ops: GQLOperation) -> JsonType:
|
||||
...
|
||||
async def request(self, ops: GQLOperation) -> JsonType: ...
|
||||
|
||||
@overload
|
||||
async def request(self, ops: list[GQLOperation]) -> list[JsonType]:
|
||||
...
|
||||
async def request(self, ops: list[GQLOperation]) -> list[JsonType]: ...
|
||||
|
||||
async def request(
|
||||
self, ops: GQLOperation | list[GQLOperation]
|
||||
) -> JsonType | list[JsonType]:
|
||||
async def request(self, ops: GQLOperation | list[GQLOperation]) -> JsonType | list[JsonType]:
|
||||
"""
|
||||
Execute one or more GraphQL operations.
|
||||
|
||||
@@ -105,9 +101,7 @@ class GQLClient:
|
||||
"POST",
|
||||
"https://gql.twitch.tv/gql",
|
||||
json=ops,
|
||||
headers=auth_state.headers(
|
||||
user_agent=self._client_type.USER_AGENT, gql=True
|
||||
),
|
||||
headers=auth_state.headers(user_agent=self._client_type.USER_AGENT, gql=True),
|
||||
) as response:
|
||||
response_json: JsonType | list[JsonType] = await response.json()
|
||||
|
||||
@@ -123,13 +117,9 @@ class GQLClient:
|
||||
if "errors" in response_json:
|
||||
for error_dict in response_json["errors"]:
|
||||
if "message" in error_dict:
|
||||
if (
|
||||
single_retry
|
||||
and error_dict["message"]
|
||||
in (
|
||||
"service error",
|
||||
"PersistedQueryNotFound",
|
||||
)
|
||||
if single_retry and error_dict["message"] in (
|
||||
"service error",
|
||||
"PersistedQueryNotFound",
|
||||
):
|
||||
logger.error(
|
||||
f"Retrying a {error_dict['message']} for "
|
||||
@@ -160,9 +150,7 @@ class GQLClient:
|
||||
raise GQLException(response_json["errors"])
|
||||
# Other error handling
|
||||
elif "error" in response_json:
|
||||
raise GQLException(
|
||||
f"{response_json['error']}: {response_json['message']}"
|
||||
)
|
||||
raise GQLException(f"{response_json['error']}: {response_json['message']}")
|
||||
|
||||
if force_retry:
|
||||
break
|
||||
|
||||
@@ -25,6 +25,7 @@ from src.utils import ExponentialBackoff
|
||||
if TYPE_CHECKING:
|
||||
from src.config import ClientInfo
|
||||
from src.config.settings import Settings
|
||||
from src.core.client import Twitch
|
||||
from src.web.gui_manager import WebGUIManager
|
||||
|
||||
|
||||
@@ -46,6 +47,7 @@ class HTTPClient:
|
||||
self,
|
||||
settings: Settings,
|
||||
gui: WebGUIManager,
|
||||
twitch: Twitch,
|
||||
client_type: ClientInfo,
|
||||
):
|
||||
"""
|
||||
@@ -56,12 +58,15 @@ class HTTPClient:
|
||||
settings : Settings
|
||||
Application settings for connection quality and proxy configuration
|
||||
gui : WebGUIManager
|
||||
GUI manager for user notifications and close detection
|
||||
GUI manager for user notifications
|
||||
twitch : Twitch
|
||||
Twitch client for state checking
|
||||
client_type : ClientInfo
|
||||
Client type information (User-Agent, Client-ID, etc.)
|
||||
"""
|
||||
self.settings = settings
|
||||
self.gui = gui
|
||||
self._twitch = twitch
|
||||
self._client_type = client_type
|
||||
self._session: aiohttp.ClientSession | None = None
|
||||
|
||||
@@ -163,7 +168,9 @@ class HTTPClient:
|
||||
backoff = ExponentialBackoff(maximum=3 * 60)
|
||||
|
||||
for delay in backoff:
|
||||
if self.gui.close_requested:
|
||||
from src.config import State
|
||||
|
||||
if self._twitch._state == State.EXIT:
|
||||
raise ExitRequest()
|
||||
elif (
|
||||
invalidate_after is not None
|
||||
@@ -174,9 +181,7 @@ class HTTPClient:
|
||||
|
||||
try:
|
||||
response: aiohttp.ClientResponse | None = None
|
||||
response = await self.gui.coro_unless_closed(
|
||||
session.request(method, url, **kwargs)
|
||||
)
|
||||
response = await session.request(method, url, **kwargs)
|
||||
assert response is not None
|
||||
logger.debug(f"Response: {response.status}: {response}")
|
||||
|
||||
@@ -203,9 +208,8 @@ class HTTPClient:
|
||||
if response is not None:
|
||||
response.release()
|
||||
|
||||
# Wait for the backoff delay or until the GUI closes
|
||||
with asyncio.suppress(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(self.gui.wait_until_closed(), timeout=delay)
|
||||
# Wait for the backoff delay
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user