From 36e1f3d65aeac95a4fc550e1ffc0525b50c923f6 Mon Sep 17 00:00:00 2001 From: twfx1207 Date: Thu, 8 Jun 2023 10:14:14 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BD=E9=99=85=E6=9C=8D?= =?UTF-8?q?=E6=8A=BD=E5=8D=A1=E8=AE=B0=E5=BD=95=E5=AF=BC=E5=85=A5=20(#58)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复国际服抽卡记录导入 * 🚨 `pre-commit-ci`修复格式错误 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- StarRailUID/sruid_utils/api/mys/api.py | 4 ++++ .../starrailuid_gachalog/get_gachalogs.py | 6 +++--- .../draw_roleinfo_card.py | 15 ++++++++------ StarRailUID/utils/mys_api.py | 20 +++++++++++++++---- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/StarRailUID/sruid_utils/api/mys/api.py b/StarRailUID/sruid_utils/api/mys/api.py index 508da13..e2fad75 100644 --- a/StarRailUID/sruid_utils/api/mys/api.py +++ b/StarRailUID/sruid_utils/api/mys/api.py @@ -1,5 +1,6 @@ # flake8: noqa OLD_URL = "https://api-takumi.mihoyo.com" +OS_OLD_URL = "https://api-os-takumi.mihoyo.com" NEW_URL = 'https://api-takumi-record.mihoyo.com' OS_URL = "https://sg-public-api.hoyolab.com" OS_INFO_URL = "https://bbs-api-os.hoyolab.com" @@ -41,6 +42,9 @@ CHALLENGE_INFO_URL = f'{NEW_URL}/game_record/app/hkrpg/api/challenge' CHALLENGE_INFO_URL_OS = f'{OS_INFO_URL}/game_record/hkrpg/api/challenge' STAR_RAIL_GACHA_LOG_URL = f'{OLD_URL}/common/gacha_record/api/getGachaLog' +STAR_RAIL_GACHA_LOG_URL_OS = ( + f'{OS_OLD_URL}/common/gacha_record/api/getGachaLog' +) GET_FP_URL = 'https://public-data-api.mihoyo.com/device-fp/api/getFp' GET_FP_URL_OS = 'https://sg-public-data-api.hoyoverse.com/device-fp/api/getFp' diff --git a/StarRailUID/starrailuid_gachalog/get_gachalogs.py b/StarRailUID/starrailuid_gachalog/get_gachalogs.py index 073b329..fddbf6a 100644 --- a/StarRailUID/starrailuid_gachalog/get_gachalogs.py +++ b/StarRailUID/starrailuid_gachalog/get_gachalogs.py @@ -16,7 +16,7 @@ gacha_type_meta_data = { async def get_new_gachalog_by_link( - gacha_url: str, full_data: Dict, is_force: bool + uid: str, gacha_url: str, full_data: Dict, is_force: bool ): temp = [] for gacha_name in gacha_type_meta_data: @@ -29,7 +29,7 @@ async def get_new_gachalog_by_link( return {} authkey = url_parse['authkey'][0] data = await mys_api.get_gacha_log_by_link_in_authkey( - authkey, gacha_type, page, end_id + uid, authkey, gacha_type, page, end_id ) await asyncio.sleep(0.45) if isinstance(data, int): @@ -105,7 +105,7 @@ async def save_gachalogs( # 获取新抽卡记录 if raw_data is None: raw_data = await get_new_gachalog_by_link( - gacha_url, gachalogs_history, is_force + uid, gacha_url, gachalogs_history, is_force ) else: new_data = {'始发跃迁': [], '群星跃迁': [], '角色跃迁': [], '光锥跃迁': []} diff --git a/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py b/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py index 79a3901..b0ba070 100644 --- a/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py +++ b/StarRailUID/starrailuid_roleinfo/draw_roleinfo_card.py @@ -195,16 +195,19 @@ async def _draw_card_2( async def draw_role_card(sr_uid: str) -> Union[bytes, str]: - role_basic_info = await mys_api.get_role_basic_info(sr_uid) role_index = await mys_api.get_role_index(sr_uid) - - if isinstance(role_index, int): - return get_error(role_index) - if isinstance(role_basic_info, int): + # deal with hoyolab with no nickname and level api + if int(str(sr_uid)[0]) < 6: + role_basic_info = await mys_api.get_role_basic_info(sr_uid) + if isinstance(role_basic_info, int): + return get_error(role_basic_info) + else: role_basic_info = {} role_basic_info['nickname'] = "开拓者" role_basic_info['level'] = 0 - # return get_error(role_basic_info) + + if isinstance(role_index, int): + return get_error(role_index) stats = role_index['stats'] avatars = role_index['avatar_list'] diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index cdafb95..5f0682d 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -108,6 +108,7 @@ class MysApi(_MysApi): async def get_gacha_log_by_link_in_authkey( self, + uid: str, authkey: str, gacha_type: str = '11', page: int = 1, @@ -115,11 +116,22 @@ class MysApi(_MysApi): ) -> Union[int, GachaLog]: # server_id = 'cn_qd01' if # uid[0] == '5' else 'cn_gf01' - server_id = 'prod_gf_cn' + server_id = RECOGNIZE_SERVER.get(str(uid)[0]) + if self.check_os(uid): + HEADER = copy.deepcopy(self._HEADER_OS) + HEADER['Cookie'] = await self.get_ck(uid, 'OWNER') + HEADER['DS'] = generate_os_ds() + header = HEADER + url = self.MAPI['STAR_RAIL_GACHA_LOG_URL_OS'] + game_biz = 'hkrpg_global' + else: + header = self._HEADER + url = self.MAPI['STAR_RAIL_GACHA_LOG_URL'] + game_biz = 'hkrpg_cn' data = await self._mys_request( - url=self.MAPI['STAR_RAIL_GACHA_LOG_URL'], + url=url, method='GET', - header=self._HEADER, + header=header, params={ 'authkey_ver': '1', 'sign_type': '2', @@ -131,7 +143,7 @@ class MysApi(_MysApi): 'plat_type': 'pc', 'region': server_id, 'authkey': authkey, - 'game_biz': 'hkrpg_cn', + 'game_biz': game_biz, 'gacha_type': gacha_type, 'page': page, 'size': '20',