Closed dontdot closed 1 year ago
我这里瞎改跑通了 你试下 /game_record/app/hkrpg/api/note 玩家信息页这里内容不全,直接换成/game_record/app/hkrpg/aapi/widget小组件了
URL_STARRAIL_STATUS_WIDGET = "https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/aapi/widget"
HEADERS_STARRAIL_STATUS_WIDGET = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh-Hans;q=0.9",
"User-Agent": _conf.device_config.USER_AGENT_WIDGET,
# "DS": None,
"Referer": "https://app.mihoyo.com",
"x-rpc-app_version": _conf.device_config.X_RPC_APP_VERSION,
"x-rpc-channel": _conf.device_config.X_RPC_CHANNEL,
"x-rpc-client_type": "2",
"x-rpc-page": '',
"x-rpc-device_fp": None,
"x-rpc-device_id": None,
"x-rpc-device_model": _conf.device_config.X_RPC_DEVICE_MODEL_MOBILE,
"x-rpc-device_name": _conf.device_config.X_RPC_DEVICE_NAME_MOBILE,
"x-rpc-sys_version": _conf.device_config.X_RPC_SYS_VERSION,
"Connection": "keep-alive",
"Host": "api-takumi-record.mihoyo.com"
}
class StarRailBoard(BaseModel):
"""
崩铁实时便笺数据 (从米游社内相关页面API的返回数据初始化)
"""
current_stamina: int
"""当前开拓力"""
max_stamina: int
"""最大开拓力"""
stamina_recover_time: int
"""剩余体力恢复时间"""
current_train_score: int
"""当前每日实训值"""
max_train_score: int
"""最大每日实训值"""
current_rogue_score: int
"""当前模拟宇宙积分"""
max_rogue_score: int
"""最大模拟宇宙积分"""
accepted_expedition_num: int
"""已接受委托数量"""
total_expedition_num: int
"""最大委托数量"""
has_signed: bool
"""当天是否签到"""
@property
def stamina_recover_text(self):
"""
剩余体力恢复文本
"""
try:
if not self.stamina_recover_time:
return '体力未获得'
elif self.stamina_recover_time == 0:
return '体力已准备就绪'
else:
return f'体力将在{datetime.fromtimestamp(int(time.time()) + self.stamina_recover_time)}恢复满值'
# m, s = divmod(self.stamina_recover_time, 60)
# h, m = divmod(m, 60)
# return f"{h} 小时 {m} 分钟 {s} 秒"
except KeyError:
return None
async def starrail_board(account: UserAccount) -> Tuple[
Union[BaseApiStatus, StarRailBoardStatus], Optional[StarRailBoard]]:
"""
获取崩铁实时便笺
:param account: 用户账户数据
"""
game_record_status, records = await get_game_record(account)
logger.info(f"genshin_board game_record_status : {game_record_status}")
logger.info(f"genshin_board records : {records}")
if not game_record_status:
return game_record_status, None
game_list_status, game_list = await get_game_list()
if not game_list_status:
return game_list_status, None
game_filter = filter(lambda x: x.en_name == 'sr', game_list)
game_info = next(game_filter, None)
if not game_info:
return StarRailBoardStatus(no_starrail_account=True), None
else:
game_id = game_info.id
flag = True
for record in records:
if record.game_id == game_id:
try:
flag = False
# params = {"role_id": record.game_role_id, "server": record.region}
# url = f"{URL_STARRAIL_STATUS_BBS}?{urlencode(params)}"
headers = HEADERS_STARRAIL_STATUS_WIDGET.copy()
url = f"{URL_STARRAIL_STATUS_WIDGET}"
# headers["x-rpc-device_id"] = account.device_id_android
async for attempt in get_async_retry(False):
with attempt:
# headers["DS"] = generate_ds(params = params)
headers["DS"] = generate_ds(data = {})
async with httpx.AsyncClient() as client:
cookies = account.cookies.dict(v2_stoken=True, cookie_type=True)
logger.info(f"starrail_board headers : {headers}")
logger.info(f"starrail_board cookies : {cookies}")
res = await client.get(url, headers=headers,
cookies=cookies,
timeout=_conf.preference.timeout)
api_result = ApiResultHandler(res.json())
logger.info(f"simple_api starrail_board api_result : {api_result}")
if api_result.login_expired:
logger.info(
f"崩铁实时便笺: 用户 {account.bbs_uid} 登录失效")
logger.debug(f"网络请求返回: {res.text}")
return StarRailBoardStatus(login_expired=True), None
if api_result.invalid_ds:
logger.info(
f"崩铁实时便笺: 用户 {account.bbs_uid} DS 校验失败")
logger.debug(f"网络请求返回: {res.text}")
if api_result.retcode == 1034:
logger.info(
f"崩铁实时便笺: 用户 {account.bbs_uid} 可能被验证码阻拦")
logger.debug(f"网络请求返回: {res.text}")
# if api_result.invalid_ds or api_result.retcode == 1034:
# headers["DS"] = generate_ds()
# headers["x-rpc-device_id"] = account.device_id_ios
# async with httpx.AsyncClient() as client:
# res = await client.get(
# URL_GENSHEN_STATUS_WIDGET,
# headers=headers,
# cookies=account.cookies.dict(v2_stoken=True, cookie_type=True),
# timeout=_conf.preference.timeout
# )
# api_result = ApiResultHandler(res.json())
# logger.info(f"崩铁实时便笺 api_result: {api_result}")
# return StarRailBoardStatus(success=True), \
# StarRailBoard.parse_obj(api_result.data)
return StarRailBoardStatus(success=True), StarRailBoard.parse_obj(api_result.data)
except tenacity.RetryError as e:
if is_incorrect_return(e):
logger.exception(f"崩铁实时便笺: 服务器没有正确返回")
logger.debug(f"网络请求返回: {res.text}")
return StarRailBoardStatus(incorrect_return=True), None
else:
logger.exception(f"崩铁实时便笺: 请求失败")
return StarRailBoardStatus(network_error=True), None
if flag:
return StarRailBoardStatus(no_genshin_account=True), None
挺好的,可以直接提交到pull request那里 https://github.com/Ljzd-PRO/nonebot-plugin-mystool/pulls
我这里瞎改跑通了 你试下 /game_record/app/hkrpg/api/note 玩家信息页这里内容不全,直接换成/game_record/app/hkrpg/aapi/widget小组件了
URL_STARRAIL_STATUS_WIDGET = "https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/aapi/widget" HEADERS_STARRAIL_STATUS_WIDGET = { "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh-Hans;q=0.9", "User-Agent": _conf.device_config.USER_AGENT_WIDGET, # "DS": None, "Referer": "https://app.mihoyo.com", "x-rpc-app_version": _conf.device_config.X_RPC_APP_VERSION, "x-rpc-channel": _conf.device_config.X_RPC_CHANNEL, "x-rpc-client_type": "2", "x-rpc-page": '', "x-rpc-device_fp": None, "x-rpc-device_id": None, "x-rpc-device_model": _conf.device_config.X_RPC_DEVICE_MODEL_MOBILE, "x-rpc-device_name": _conf.device_config.X_RPC_DEVICE_NAME_MOBILE, "x-rpc-sys_version": _conf.device_config.X_RPC_SYS_VERSION, "Connection": "keep-alive", "Host": "api-takumi-record.mihoyo.com" }
class StarRailBoard(BaseModel): """ 崩铁实时便笺数据 (从米游社内相关页面API的返回数据初始化) """ current_stamina: int """当前开拓力""" max_stamina: int """最大开拓力""" stamina_recover_time: int """剩余体力恢复时间""" current_train_score: int """当前每日实训值""" max_train_score: int """最大每日实训值""" current_rogue_score: int """当前模拟宇宙积分""" max_rogue_score: int """最大模拟宇宙积分""" accepted_expedition_num: int """已接受委托数量""" total_expedition_num: int """最大委托数量""" has_signed: bool """当天是否签到""" @property def stamina_recover_text(self): """ 剩余体力恢复文本 """ try: if not self.stamina_recover_time: return '体力未获得' elif self.stamina_recover_time == 0: return '体力已准备就绪' else: return f'体力将在{datetime.fromtimestamp(int(time.time()) + self.stamina_recover_time)}恢复满值' # m, s = divmod(self.stamina_recover_time, 60) # h, m = divmod(m, 60) # return f"{h} 小时 {m} 分钟 {s} 秒" except KeyError: return None
async def starrail_board(account: UserAccount) -> Tuple[ Union[BaseApiStatus, StarRailBoardStatus], Optional[StarRailBoard]]: """ 获取崩铁实时便笺 :param account: 用户账户数据 """ game_record_status, records = await get_game_record(account) logger.info(f"genshin_board game_record_status : {game_record_status}") logger.info(f"genshin_board records : {records}") if not game_record_status: return game_record_status, None game_list_status, game_list = await get_game_list() if not game_list_status: return game_list_status, None game_filter = filter(lambda x: x.en_name == 'sr', game_list) game_info = next(game_filter, None) if not game_info: return StarRailBoardStatus(no_starrail_account=True), None else: game_id = game_info.id flag = True for record in records: if record.game_id == game_id: try: flag = False # params = {"role_id": record.game_role_id, "server": record.region} # url = f"{URL_STARRAIL_STATUS_BBS}?{urlencode(params)}" headers = HEADERS_STARRAIL_STATUS_WIDGET.copy() url = f"{URL_STARRAIL_STATUS_WIDGET}" # headers["x-rpc-device_id"] = account.device_id_android async for attempt in get_async_retry(False): with attempt: # headers["DS"] = generate_ds(params = params) headers["DS"] = generate_ds(data = {}) async with httpx.AsyncClient() as client: cookies = account.cookies.dict(v2_stoken=True, cookie_type=True) logger.info(f"starrail_board headers : {headers}") logger.info(f"starrail_board cookies : {cookies}") res = await client.get(url, headers=headers, cookies=cookies, timeout=_conf.preference.timeout) api_result = ApiResultHandler(res.json()) logger.info(f"simple_api starrail_board api_result : {api_result}") if api_result.login_expired: logger.info( f"崩铁实时便笺: 用户 {account.bbs_uid} 登录失效") logger.debug(f"网络请求返回: {res.text}") return StarRailBoardStatus(login_expired=True), None if api_result.invalid_ds: logger.info( f"崩铁实时便笺: 用户 {account.bbs_uid} DS 校验失败") logger.debug(f"网络请求返回: {res.text}") if api_result.retcode == 1034: logger.info( f"崩铁实时便笺: 用户 {account.bbs_uid} 可能被验证码阻拦") logger.debug(f"网络请求返回: {res.text}") # if api_result.invalid_ds or api_result.retcode == 1034: # headers["DS"] = generate_ds() # headers["x-rpc-device_id"] = account.device_id_ios # async with httpx.AsyncClient() as client: # res = await client.get( # URL_GENSHEN_STATUS_WIDGET, # headers=headers, # cookies=account.cookies.dict(v2_stoken=True, cookie_type=True), # timeout=_conf.preference.timeout # ) # api_result = ApiResultHandler(res.json()) # logger.info(f"崩铁实时便笺 api_result: {api_result}") # return StarRailBoardStatus(success=True), \ # StarRailBoard.parse_obj(api_result.data) return StarRailBoardStatus(success=True), StarRailBoard.parse_obj(api_result.data) except tenacity.RetryError as e: if is_incorrect_return(e): logger.exception(f"崩铁实时便笺: 服务器没有正确返回") logger.debug(f"网络请求返回: {res.text}") return StarRailBoardStatus(incorrect_return=True), None else: logger.exception(f"崩铁实时便笺: 请求失败") return StarRailBoardStatus(network_error=True), None if flag: return StarRailBoardStatus(no_genshin_account=True), None
根据你这个,我也弄好了<3
挺好的,可以直接提交到pull request那里 https://github.com/Ljzd-PRO/nonebot-plugin-mystool/pulls
要不我来pull下吧 @RemiDre
挺好的,可以直接提交到pull request那里 https://github.com/Ljzd-PRO/nonebot-plugin-mystool/pulls
要不我来pull下吧 @RemiDre
ok
@Ljzd-PRO 自动检查便笺那里,异步函数要怎么改能让同时原神和崩铁一起运行
如果是每小时自动执行的话,在这里像resin_check那样加上崩铁的就可以
如果是每小时自动执行的话,在这里像resin_check那样加上崩铁的就可以
这个现在已经加上了
如果是每小时自动执行的话,在这里像resin_check那样加上崩铁的就可以
这个现在已经加上了
plan.resin_check_sr的函数的推送可能有点问题
07-19 14:34:29 [INFO] nonebot_plugin_mystool | 原神实时便笺: 用户 123 可能被验证码阻拦
07-19 14:34:29 [DEBUG] nonebot_plugin_mystool | 网络请求返回: {"data":null,"message":"","retcode":1034}
07-19 14:34:30 [INFO] nonebot_plugin_mystool | success=True network_error=False incorrect_return=False login_expired=False need_verify=False invalid_ds=False no_genshin_account=False
07-19 14:34:31 [DEBUG] nonebot | OneBot V11 | Calling API send_private_msg
07-19 14:34:37 [INFO] nonebot_plugin_mystool | success=True network_error=False incorrect_return=False login_expired=False need_verify=False invalid_ds=False no_starrail_account=False
有显示starrail相关的信息,resin_check_sr应该有运行的,有可能是后面的msg相关的出问题导致没有推送
后续有计划做星穹铁道的便笺吗?我尝试自己去添加,结果返回的内容是
我添加了
game_list和game_records都成功返回内容,但是倒在了这里
下面是终端上的错误信息