Centralize Douyu client creation, CK session probing, identity refresh, role alias resolution, capability persistence, cache and batch throttling across collaboration, fulfillment, tasks and cookie management. Add the account-name copy action in the collaboration table.
254 lines
5.8 KiB
Python
254 lines
5.8 KiB
Python
"""斗鱼活动只读查询的唯一入口。
|
|
|
|
账号角色、精英宝典状态、活动商品、积分、限兑商品、鱼翅和官方记录
|
|
都在这里调用 ``DouyuActivityClient``。业务模块只消费归一化结果,不直接
|
|
拼接口参数或解析响应,避免工作台、协作台账和任务执行器各自漂移。
|
|
|
|
兑换、充值、锁定订单等写操作不在这里实现;它们继续由任务执行器负责。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from core.douyu import DouyuActivityClient
|
|
|
|
|
|
def activity_client(
|
|
cookie: str = "",
|
|
*,
|
|
logger_callback: Callable[[str], None] | None = None,
|
|
proxies: dict[str, str] | None = None,
|
|
) -> DouyuActivityClient:
|
|
"""创建统一活动客户端;空 Cookie 可用于公开商品目录查询。"""
|
|
return DouyuActivityClient(
|
|
cookie,
|
|
logger=logger_callback,
|
|
proxies=proxies,
|
|
)
|
|
|
|
|
|
def query_csrf(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
refresh_subscribe: bool = False,
|
|
) -> str:
|
|
return client.acf_ccn(refresh_subscribe=refresh_subscribe)
|
|
|
|
|
|
def query_elite_user_info(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str = "",
|
|
) -> dict[str, Any]:
|
|
return client.elite_user_info(manual_id=manual_id, rid=rid)
|
|
|
|
|
|
def query_bind_info(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
act_alias: str,
|
|
v2: bool = False,
|
|
) -> dict[str, Any]:
|
|
return client.bind_info(act_alias=act_alias, v2=v2)
|
|
|
|
|
|
def query_esports_bind_info(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
act_alias: str,
|
|
) -> dict[str, Any]:
|
|
return client.esports_bind_info(act_alias=act_alias)
|
|
|
|
|
|
def query_xpd_bind_info(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
act_alias: str,
|
|
) -> dict[str, Any]:
|
|
return client.xpd_bind_info(act_alias=act_alias)
|
|
|
|
|
|
def query_xpd_embed(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
act_alias: str,
|
|
rid: str,
|
|
) -> dict[str, Any]:
|
|
return client.xpd_embed_query(act_alias=act_alias, rid=rid)
|
|
|
|
|
|
def query_xpd_role(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
embed_query: dict[str, str],
|
|
act_id: str,
|
|
rid: str = "",
|
|
) -> dict[str, Any]:
|
|
return client.xpd_get_role(
|
|
embed_query=embed_query,
|
|
act_id=act_id,
|
|
rid=rid,
|
|
)
|
|
|
|
|
|
def query_gold_account(client: DouyuActivityClient) -> dict[str, Any]:
|
|
return client.gold_account()
|
|
|
|
|
|
def query_exchange_balance(client: DouyuActivityClient) -> dict[str, Any]:
|
|
return client.exchange_balance()
|
|
|
|
|
|
def query_activity_goods(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str,
|
|
) -> list[dict[str, Any]]:
|
|
result = client.list_goods(manual_id=manual_id, rid=rid)
|
|
return [dict(item) for item in result.get("goods") or [] if isinstance(item, dict)]
|
|
|
|
|
|
def query_esports_goods_result(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str,
|
|
) -> dict[str, Any]:
|
|
return client.list_esports_goods(manual_id=manual_id, rid=rid)
|
|
|
|
|
|
def query_esports_goods(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str,
|
|
) -> list[dict[str, Any]]:
|
|
result = query_esports_goods_result(
|
|
client,
|
|
manual_id=manual_id,
|
|
rid=rid,
|
|
)
|
|
return [dict(item) for item in result.get("goods") or [] if isinstance(item, dict)]
|
|
|
|
|
|
def query_points(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
uid: str,
|
|
ctn: str,
|
|
) -> dict[str, Any]:
|
|
return client.query_points(uid=uid, ctn=ctn)
|
|
|
|
|
|
def query_limited_goods_result(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str,
|
|
) -> dict[str, Any]:
|
|
return client.query_limited_goods(manual_id=manual_id, rid=rid)
|
|
|
|
|
|
def query_limited_goods(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
rid: str,
|
|
) -> list[dict[str, Any]]:
|
|
result = query_limited_goods_result(client, manual_id=manual_id, rid=rid)
|
|
return [
|
|
dict(item)
|
|
for item in result.get("limited_goods") or []
|
|
if isinstance(item, dict)
|
|
]
|
|
|
|
|
|
def query_exchange_records_result(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
limit: int = 100,
|
|
offset: int = 0,
|
|
) -> dict[str, Any]:
|
|
return client.exchange_records(
|
|
manual_id=manual_id,
|
|
limit=limit,
|
|
offset=offset,
|
|
)
|
|
|
|
|
|
def query_exchange_records(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
limit: int = 100,
|
|
offset: int = 0,
|
|
) -> list[dict[str, Any]]:
|
|
result = query_exchange_records_result(
|
|
client,
|
|
manual_id=manual_id,
|
|
limit=limit,
|
|
offset=offset,
|
|
)
|
|
return [
|
|
dict(item) for item in result.get("records") or [] if isinstance(item, dict)
|
|
]
|
|
|
|
|
|
def query_exchange_orders_result(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
page: int = 1,
|
|
page_size: int = 10,
|
|
) -> dict[str, Any]:
|
|
return client.exchange_orders(
|
|
manual_id=manual_id,
|
|
page=page,
|
|
page_size=page_size,
|
|
)
|
|
|
|
|
|
def query_exchange_orders(
|
|
client: DouyuActivityClient,
|
|
*,
|
|
manual_id: str,
|
|
page: int = 1,
|
|
page_size: int = 10,
|
|
) -> list[dict[str, Any]]:
|
|
result = query_exchange_orders_result(
|
|
client,
|
|
manual_id=manual_id,
|
|
page=page,
|
|
page_size=page_size,
|
|
)
|
|
return [dict(item) for item in result.get("orders") or [] if isinstance(item, dict)]
|
|
|
|
|
|
__all__ = [
|
|
"activity_client",
|
|
"query_activity_goods",
|
|
"query_bind_info",
|
|
"query_csrf",
|
|
"query_elite_user_info",
|
|
"query_esports_bind_info",
|
|
"query_esports_goods",
|
|
"query_esports_goods_result",
|
|
"query_exchange_balance",
|
|
"query_exchange_orders",
|
|
"query_exchange_orders_result",
|
|
"query_exchange_records",
|
|
"query_exchange_records_result",
|
|
"query_gold_account",
|
|
"query_limited_goods",
|
|
"query_limited_goods_result",
|
|
"query_points",
|
|
"query_xpd_bind_info",
|
|
"query_xpd_embed",
|
|
"query_xpd_role",
|
|
]
|