Skip to content

Commit

Permalink
✨ 初步支持导入UIGFv4格式的数据 (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Aug 13, 2024
1 parent 1dff173 commit 9d4270d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
64 changes: 46 additions & 18 deletions GenshinUID/genshinuid_gachalog/export_and_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
from copy import deepcopy
from datetime import datetime
from typing import Dict, List

from httpx import get

Expand All @@ -18,11 +19,25 @@
}


async def import_data(uid: str, raw_data: List[Dict]):
result = deepcopy(NULL_GACHA_LOG)
for item in raw_data:
item['uid'] = uid
item['item_id'] = ''
item['count'] = '1'
item['lang'] = 'zh-cn'
item['id'] = str(item['id'])
del item['uigf_gacha_type']
result[INT_TO_TYPE[item['gacha_type']]].append(item)
return result


async def import_gachalogs(history_url: str, type: str, uid: str) -> str:
history_data: Dict = {}
if type == 'url':
history_data: dict = json.loads(get(history_url).text)
history_data = json.loads(get(history_url).text)
elif type == 'json':
history_data: dict = json.loads(history_url)
history_data = json.loads(history_url)
if history_data.get('code') == 300:
return "[提瓦特小助手]抽卡记录不存在"
else:
Expand All @@ -33,22 +48,35 @@ async def import_gachalogs(history_url: str, type: str, uid: str) -> str:
history_data = json.loads(data_bytes.decode('gbk'))
except json.decoder.JSONDecodeError:
return '请传入正确的JSON格式文件!'
if 'info' in history_data and 'uid' in history_data['info']:
data_uid = history_data['info']['uid']
if data_uid != uid:
return f'该抽卡记录UID{data_uid}与你绑定UID{uid}不符合!'
raw_data = history_data['list']
result = deepcopy(NULL_GACHA_LOG)
for item in raw_data:
item['uid'] = uid
item['item_id'] = ''
item['count'] = '1'
item['lang'] = 'zh-cn'
item['id'] = str(item['id'])
del item['uigf_gacha_type']
result[INT_TO_TYPE[item['gacha_type']]].append(item)
im = await save_gachalogs(uid, result)
return im
if 'info' in history_data and 'version' in history_data['info']:
_version: str = str(history_data['info']['version'])
_version = _version.replace('version', '').replace('v', '')
try:
version = float(_version)
except ValueError:
return '请传入正确的UIGF文件!'

if version >= 4.0:
if 'hk4e' in history_data:
im = ''
for sdata in history_data['hk4e']:
data_uid = sdata['uid']
result = await import_data(uid, sdata['list'])
im += await save_gachalogs(uid, result)
return im
else:
return '你当前导入的UIGF文件不包含原神的抽卡数据, 请检查!'
else:
if 'uid' in history_data['info']:
data_uid = history_data['info']['uid']
if data_uid != uid:
return f'该抽卡记录UID{data_uid}与你绑定UID{uid}不符合!'
raw_data = history_data['list']
result = await import_data(uid, raw_data)
im = await save_gachalogs(uid, result)
return im
else:
return '请传入正确的UIGF文件!'
else:
return '请传入正确的UIGF文件!'

Expand Down
8 changes: 4 additions & 4 deletions GenshinUID/genshinuid_resin/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
MR_NOTICE = '\n✅可发送[mr]或者[每日]来查看更多信息!\n'

NOTICE = {
'coin': '你的洞天宝钱快满啦!',
'resin': '你的树脂/体力快满啦!',
'go': '你有派遣奖励即将可领取!',
'transform': '你的质变仪即将可使用!',
'coin': '💰你的洞天宝钱快满啦!',
'resin': '🌜你的树脂/体力快满啦!',
'go': '👨‍🏭你有派遣奖励即将可领取!',
'transform': '你的质变仪即将可使用!',
}


Expand Down

0 comments on commit 9d4270d

Please sign in to comment.