修复国际服抽卡记录导入 (#58)

* 修复国际服抽卡记录导入

* 🚨 `pre-commit-ci`修复格式错误

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
twfx1207 2023-06-08 10:14:14 +09:00 committed by GitHub
parent 3904324153
commit 36e1f3d65a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 13 deletions

View File

@ -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'

View File

@ -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 = {'始发跃迁': [], '群星跃迁': [], '角色跃迁': [], '光锥跃迁': []}

View File

@ -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']

View File

@ -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',