Skip to content

Commit

Permalink
feat(add): pusher | DLC claimer
Browse files Browse the repository at this point in the history
1. 添加断言状态 `GAME_NOT_FREE` #56 ;
2. 添加参数 `claim --ignore` 当所有资源实体已在库时忽略推送 #55 ;
3. 微调程序架构;
  • Loading branch information
QIN2DIM committed Apr 3, 2022
1 parent c7220fc commit ea61162
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 146 deletions.
7 changes: 4 additions & 3 deletions src/apis/scaffold/claimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Description:
from typing import Optional

from services.deploy import ClaimerScheduler
from services.deploy import ClaimerScheduler, ClaimerInstance
from services.settings import logger


Expand All @@ -16,6 +16,7 @@ def deploy(platform: Optional[str] = None):


@logger.catch()
def run(silence: Optional[bool] = None):
def run(silence: Optional[bool] = None, log_ignore: Optional[bool] = None):
"""运行 `claim` 单步子任务,认领周免游戏"""
ClaimerScheduler(silence=silence).job_loop_claim()
with ClaimerInstance(silence=silence, log_ignore=log_ignore) as claimer:
claimer.just_do_it()
3 changes: 0 additions & 3 deletions src/services/bricklayer/bricklayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ def __init__(self, silence: bool = None):

self.cookie_manager = CookieManager()

# 游戏获取结果的状态
self.result = ""

def get_free_game(
self,
page_link: str,
Expand Down
20 changes: 15 additions & 5 deletions src/services/bricklayer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import List, Optional, NoReturn, Dict

import cloudscraper
from requests.exceptions import RequestException
from selenium.common.exceptions import (
TimeoutException,
ElementNotVisibleException,
Expand Down Expand Up @@ -87,11 +88,16 @@ def _ajax_cookie_check_need_login(beat_dance: int = 0) -> Optional[bool]:
scraper = cloudscraper.create_scraper()
try:
response = scraper.get(
_api, headers={"cookie": ToolBox.transfer_cookies(ctx.get_cookies())}
_api,
headers={"cookie": ToolBox.transfer_cookies(ctx.get_cookies())},
timeout=2,
)
return response.json()["needLogin"]
except (json.decoder.JSONDecodeError, KeyError):
return True
# Timeout/ConnectionError
except RequestException:
return True
except Exception as err: # noqa
logger.warning(err)
return None
Expand Down Expand Up @@ -131,11 +137,11 @@ def fall_in_captcha_runtime(ctx: Chrome) -> Optional[bool]:
"""
判断在下单时是否遇到人机挑战
# "//div[@id='talon_frame_checkout_free_prod']"
:param ctx:
:return:
"""
try:
# "//div[@id='talon_frame_checkout_free_prod']"
WebDriverWait(ctx, 5, ignored_exceptions=WebDriverException).until(
EC.presence_of_element_located(
(By.XPATH, "//iframe[contains(@title,'content')]")
Expand Down Expand Up @@ -368,6 +374,7 @@ class AssertUtils:
GAME_OK = "🛴 已在库"
GAME_PENDING = "👀 待认领"
GAME_CLAIM = "💰 领取成功"
GAME_NOT_FREE = "🦽 付费游戏"

@staticmethod
def login_error(ctx: Chrome) -> bool:
Expand Down Expand Up @@ -645,7 +652,7 @@ def purchase_status(
game=f"『{game_name}』",
)
)
return AssertUtils.ASSERT_OBJECT_EXCEPTION
return AssertUtils.GAME_NOT_FREE

return AssertUtils.ASSERT_OBJECT_EXCEPTION

Expand Down Expand Up @@ -687,6 +694,9 @@ def __init__(self):
self.path_ctx_cookies = os.path.join(DIR_COOKIES, "ctx_cookies.yaml")
self.loop_timeout = 300

# 游戏获取结果的状态
self.result = ""

# 注册拦截机
self._armor = ArmorUtils()
self.assert_ = AssertUtils()
Expand Down Expand Up @@ -880,10 +890,10 @@ def _get_free_game(
# 当游戏不处于<待认领>状态时跳过后续业务
if self.result != self.assert_.GAME_PENDING:
# <游戏状态断言超时>或<检测到异常的实体对象>
# # 在超时阈值内尝试重新拉起服务
# 在超时阈值内尝试重新拉起服务
if self.result == self.assert_.ASSERT_OBJECT_EXCEPTION:
continue
# 否则游戏状态处于<领取成功>或<已在库>
# 否则游戏状态处于<领取成功>或<已在库>或<付费游戏>
break

# [🚀] 激活游戏订单
Expand Down
Loading

0 comments on commit ea61162

Please sign in to comment.