统一推送前Python代码格式
This commit is contained in:
@@ -76,7 +76,10 @@ class HuyaBatchRunnerCore:
|
||||
missing = self._web_wss_cookie_missing(cookie)
|
||||
if missing:
|
||||
detail = ", ".join(missing)
|
||||
self._push_log("error", f"[{uid}] Cookie 缺少网页设备态({detail}),已停止活动 HTTP 回退")
|
||||
self._push_log(
|
||||
"error",
|
||||
f"[{uid}] Cookie 缺少网页设备态({detail}),已停止活动 HTTP 回退",
|
||||
)
|
||||
raise RuntimeError(f"COOKIE_INCOMPLETE: 缺少网页设备态({detail})")
|
||||
session = self._open_wss_session(uid, cookie, "activity")
|
||||
self._push_log("info", f"[{uid}] 活动链路使用 WSS 会话")
|
||||
@@ -92,8 +95,14 @@ class HuyaBatchRunnerCore:
|
||||
不阻断 WSS(风控风险自担)。
|
||||
"""
|
||||
required = (
|
||||
"udb_cred", "udb_biztoken", "udb_uid", "yyuid", "sdid",
|
||||
"udb_deviceid", "udb_guiddata", "udb_anobiztoken",
|
||||
"udb_cred",
|
||||
"udb_biztoken",
|
||||
"udb_uid",
|
||||
"yyuid",
|
||||
"sdid",
|
||||
"udb_deviceid",
|
||||
"udb_guiddata",
|
||||
"udb_anobiztoken",
|
||||
)
|
||||
return tuple(key for key in required if not cookie_value(cookie, key))
|
||||
|
||||
@@ -107,7 +116,10 @@ class HuyaBatchRunnerCore:
|
||||
missing = self._web_wss_cookie_missing(cookie)
|
||||
if missing:
|
||||
detail = ", ".join(missing)
|
||||
self._push_log("error", f"[{uid}] Cookie 缺少网页设备态({detail}),已停止商城 HTTP 回退")
|
||||
self._push_log(
|
||||
"error",
|
||||
f"[{uid}] Cookie 缺少网页设备态({detail}),已停止商城 HTTP 回退",
|
||||
)
|
||||
raise RuntimeError(f"COOKIE_INCOMPLETE: 缺少网页设备态({detail})")
|
||||
session = self._open_wss_session(uid, cookie, "shop")
|
||||
self._push_log("info", f"[{uid}] 商城链路使用 WSS 会话")
|
||||
@@ -243,7 +255,9 @@ class HuyaBatchRunnerCore:
|
||||
"result": result,
|
||||
"created_by": task.created_by,
|
||||
"created_at": task.created_at.isoformat() if task.created_at else None,
|
||||
"finished_at": task.finished_at.isoformat() if task.finished_at else None,
|
||||
"finished_at": task.finished_at.isoformat()
|
||||
if task.finished_at
|
||||
else None,
|
||||
},
|
||||
}
|
||||
asyncio.run_coroutine_threadsafe(self.log_queue.put(event), self.loop)
|
||||
|
||||
@@ -56,7 +56,9 @@ class GoodsMixin:
|
||||
result = response.to_dict()
|
||||
result["act_id"] = act_id
|
||||
act_info = client.get_act_info(act_id=act_id)
|
||||
user_tasks = client.get_act_user_task_detail(uid=uid, cookie=cookie, act_id=act_id)
|
||||
user_tasks = client.get_act_user_task_detail(
|
||||
uid=uid, cookie=cookie, act_id=act_id
|
||||
)
|
||||
if act_info is not None:
|
||||
result["act_info"] = act_info.to_dict()
|
||||
if user_tasks is not None:
|
||||
@@ -347,20 +349,28 @@ class GoodsMixin:
|
||||
return
|
||||
now_ts = int(time.time())
|
||||
if prize.isCanExchange == 0:
|
||||
self._mark_task(worker_db, task, "failed", "该商品当前不可兑换", detail_result)
|
||||
self._mark_task(
|
||||
worker_db, task, "failed", "该商品当前不可兑换", detail_result
|
||||
)
|
||||
return
|
||||
if prize.isShowNum and prize.leftNum <= 0:
|
||||
self._mark_task(worker_db, task, "failed", "该商品库存不足", detail_result)
|
||||
return
|
||||
if prize.exchangeStartTime and now_ts < prize.exchangeStartTime:
|
||||
self._mark_task(worker_db, task, "failed", "该商品尚未开始兑换", detail_result)
|
||||
self._mark_task(
|
||||
worker_db, task, "failed", "该商品尚未开始兑换", detail_result
|
||||
)
|
||||
return
|
||||
if prize.exchangeEndTime and now_ts > prize.exchangeEndTime:
|
||||
self._mark_task(worker_db, task, "failed", "该商品兑换已结束", detail_result)
|
||||
self._mark_task(
|
||||
worker_db, task, "failed", "该商品兑换已结束", detail_result
|
||||
)
|
||||
return
|
||||
score = client.query_user_score(uid=uid, cookie=cookie, sid=sid_int)
|
||||
if score is None:
|
||||
self._mark_task(worker_db, task, "error", "兑换前积分查询无响应", detail_result)
|
||||
self._mark_task(
|
||||
worker_db, task, "error", "兑换前积分查询无响应", detail_result
|
||||
)
|
||||
return
|
||||
if score.status != 200 or score.available_score < prize.newScore:
|
||||
detail_result["score"] = score.to_dict()
|
||||
@@ -396,7 +406,9 @@ class GoodsMixin:
|
||||
return
|
||||
|
||||
post_score = client.query_user_score(uid=uid, cookie=cookie, sid=sid_int)
|
||||
post_records = client.get_user_prize_records(uid=uid, cookie=cookie, sid=sid_int)
|
||||
post_records = client.get_user_prize_records(
|
||||
uid=uid, cookie=cookie, sid=sid_int
|
||||
)
|
||||
if post_score is not None:
|
||||
result["post_exchange_score"] = post_score.to_dict()
|
||||
account.points = post_score.available_score
|
||||
|
||||
@@ -109,7 +109,9 @@ class RechargeMixin:
|
||||
"payment_checked_at": checked_at,
|
||||
"payment_order": last_order,
|
||||
"payment_order_status": status,
|
||||
"payment_order_status_label": self._huya_order_status_label(status),
|
||||
"payment_order_status_label": self._huya_order_status_label(
|
||||
status
|
||||
),
|
||||
}
|
||||
)
|
||||
if self._is_huya_order_paid(order):
|
||||
@@ -125,25 +127,39 @@ class RechargeMixin:
|
||||
else:
|
||||
# 兼容旧 HTTP 网关不提供 orderDetailV5 的情况。
|
||||
resp = client.query_user_order_list(
|
||||
uid=uid, guid=guid, cookie=cookie, offset=0, page_size=10,
|
||||
order_type=1, status=0, timeout=10.0,
|
||||
uid=uid,
|
||||
guid=guid,
|
||||
cookie=cookie,
|
||||
offset=0,
|
||||
page_size=10,
|
||||
order_type=1,
|
||||
status=0,
|
||||
timeout=10.0,
|
||||
)
|
||||
for legacy_order in getattr(resp, "orders", []) if resp else []:
|
||||
if str(getattr(legacy_order, "orderId", "")) != order_id_text:
|
||||
continue
|
||||
last_order = legacy_order.to_dict()
|
||||
status = int(getattr(legacy_order, "orderStatus", 0) or 0)
|
||||
result.update({
|
||||
"payment_checked_at": checked_at,
|
||||
"payment_order": last_order,
|
||||
"payment_order_status": status,
|
||||
"payment_order_status_label": self._huya_order_status_label(status),
|
||||
})
|
||||
result.update(
|
||||
{
|
||||
"payment_checked_at": checked_at,
|
||||
"payment_order": last_order,
|
||||
"payment_order_status": status,
|
||||
"payment_order_status_label": self._huya_order_status_label(
|
||||
status
|
||||
),
|
||||
}
|
||||
)
|
||||
if self._is_huya_order_paid(legacy_order):
|
||||
result.update({
|
||||
"payment_status": "paid", "payment_status_label": "已支付",
|
||||
"payment_paid": True, "payment_paid_at": checked_at,
|
||||
})
|
||||
result.update(
|
||||
{
|
||||
"payment_status": "paid",
|
||||
"payment_status_label": "已支付",
|
||||
"payment_paid": True,
|
||||
"payment_paid_at": checked_at,
|
||||
}
|
||||
)
|
||||
return "paid", last_order
|
||||
result.setdefault("payment_checked_at", checked_at)
|
||||
if self._stop.wait(HUYA_PAYMENT_POLL_INTERVAL):
|
||||
@@ -309,7 +325,8 @@ class RechargeMixin:
|
||||
|
||||
worker_db.query(HuyaRechargeGoodsSnapshot).filter(
|
||||
HuyaRechargeGoodsSnapshot.account_id == account.id,
|
||||
HuyaRechargeGoodsSnapshot.sid == (self._to_int(config_info.get("sid")) or 2203),
|
||||
HuyaRechargeGoodsSnapshot.sid
|
||||
== (self._to_int(config_info.get("sid")) or 2203),
|
||||
).delete(synchronize_session=False)
|
||||
for item in goods:
|
||||
worker_db.add(
|
||||
@@ -386,7 +403,8 @@ class RechargeMixin:
|
||||
worker_db.query(HuyaRechargeGoodsSnapshot)
|
||||
.filter(
|
||||
HuyaRechargeGoodsSnapshot.account_id == account.id,
|
||||
HuyaRechargeGoodsSnapshot.sid == (self._to_int(config_info.get("sid")) or 2203),
|
||||
HuyaRechargeGoodsSnapshot.sid
|
||||
== (self._to_int(config_info.get("sid")) or 2203),
|
||||
HuyaRechargeGoodsSnapshot.spu_id == spu_id,
|
||||
)
|
||||
.first()
|
||||
@@ -442,7 +460,9 @@ class RechargeMixin:
|
||||
protocol = client.check_hy_protocol(uid=uid, guid="", cookie=cookie)
|
||||
if protocol is None or protocol.code != 200:
|
||||
self._mark_task(
|
||||
worker_db, task, "failed",
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
getattr(protocol, "message", "商城协议校验失败") or "商城协议校验失败",
|
||||
{"goods": detail, "protocol": protocol.to_dict() if protocol else None},
|
||||
)
|
||||
@@ -451,9 +471,16 @@ class RechargeMixin:
|
||||
uid=uid, guid="", cookie=cookie, spu_id=spu_id, sku_id=0
|
||||
)
|
||||
available_channels = set(getattr(channels, "channels", []) or [])
|
||||
if channels is None or channels.code != 200 or pay_channel not in available_channels:
|
||||
if (
|
||||
channels is None
|
||||
or channels.code != 200
|
||||
or pay_channel not in available_channels
|
||||
):
|
||||
self._mark_task(
|
||||
worker_db, task, "failed", "当前支付渠道不可用",
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
"当前支付渠道不可用",
|
||||
{"goods": detail, "channels": channels.to_dict() if channels else None},
|
||||
)
|
||||
return
|
||||
@@ -462,7 +489,9 @@ class RechargeMixin:
|
||||
)
|
||||
if auth is None or auth.code != 200:
|
||||
self._mark_task(
|
||||
worker_db, task, "failed",
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
getattr(auth, "message", "购买权限校验失败") or "购买权限校验失败",
|
||||
{"goods": detail, "auth": auth.to_dict() if auth else None},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user