littlenyima / honkai-starrail-toolkit Goto Github PK
View Code? Open in Web Editor NEW《崩坏:星穹铁道》工具箱,支持抽卡分析、帧率解锁等功能
Home Page: https://pypi.org/project/starrail-toolkit/
License: GNU General Public License v3.0
《崩坏:星穹铁道》工具箱,支持抽卡分析、帧率解锁等功能
Home Page: https://pypi.org/project/starrail-toolkit/
License: GNU General Public License v3.0
抽卡记录是通过参数end_id
和size
来检索,而不是通过page
,你的请求只改动page
是没用的。你用postman测一下大概就明白我说的什么意思了。
readme中 写道:
获取抽卡查询 API URL
由此可以获得一个形如 https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?xxxxx 的 URL,后续步骤使用的就是这个 URL。注意:API URL 会在一定时间后过期,过期后需要重新获取。
请问一下 由此可以获得 这个由此是哪里?
get_cache_path
函数,米哈游偷偷改了cache文件的存储路径规则,改为按照版本号生成,建议改成
def get_cache_path(game_install_path):
from functools import cmp_to_key
def cmp(ver_a: str, ver_b: str):
ver_a = ver_a.split('.')
ver_b = ver_b.split('.')
ver_a = [int(a) for a in ver_a]
ver_b = [int(b) for b in ver_b]
length = min(len(ver_a), len(ver_b))
for i in range(length):
if ver_a[i] != ver_b[i]:
return ver_b[i] - ver_a[i]
return len(ver_b) - len(ver_a)
logger.info('Getting gacha query cache path')
cache_path = os.path.join(
game_install_path,
'StarRail_Data', 'webCaches'
)
maybe_dirs = os.listdir(cache_path)
# 排序,要版本号大的在前
maybe_dirs = sorted(maybe_dirs, key=cmp_to_key(cmp))
cache_path = os.path.join(
cache_path,
maybe_dirs[0],
'Cache',
'Cache_Data',
'data_2'
)
if not os.path.exists(cache_path):
error_msg = (
f'Cache path {cache_path} is not existing. Please visit '
'the gacha querying page before exporting gacha data.'
)
logger.error(error_msg)
return cache_path
关于windows上无法打开被占用文件的问题,建议改成robocopy来复制,get_api_from_cache
建议改成
def get_api_from_cache(cache_path):
def get_api_form_cache_windows(cache_path):
tmpdir_path='{}\\tmp'.format(os.path.abspath('.'))
try:
if os.path.exists(tmpdir_path) and os.path.isfile(tmpdir_path):
tmpdir_path='{}{:0>4d}'.format(tmpdir_path, int(time.time()) % 10000)
os.mkdir(tmpdir_path)
if not os.path.exists(tmpdir_path):
os.mkdir(tmpdir_path)
except BaseException as E:
logger.error('TODO20240413:{}'.format(E))
else:
cmd = 'robocopy "{}" "{}" data_2'.format(os.path.dirname(cache_path), tmpdir_path)
res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
res.wait(5)
assert 0==res.returncode, res.stderr.read()
cache_path='{}\\data_2'.format(tmpdir_path)
logger.info('Creating tmp file ok')
return cache_path
logger.info('Getting api URL from cache')
import os, time, subprocess
if os.name.startswith('nt'):
cache_path = get_api_form_cache_windows(cache_path)
with open(cache_path, 'rb') as f_cache:
cache = f_cache.read()
parts = cache.split(b'1/0/')
parts = [part.split(b'\x00')[0].decode(errors='ignore') for part in parts]
parts = map(get_url_from_text, parts)
parts = list(filter(bool, parts))
if not parts:
error_msg = (
'API URL is not found in cache. Please visit the gacha querying '
'page before exporting gacha data.'
)
logger.error(error_msg)
return ''
return get_latest_url(parts)
在python3.9,崩铁2.22,windows10上测试了以上修改是ok的,希望版本能够更新一下,谢谢,懒得提merge请求了
怎么把api导入到抽卡分析工具里面?我在工具界面好像没有看到导入api的入口,教程里面也没有看到方法。可以在教程里面添加一下使用方法吗?
get_cache_path
函数,米哈游偷偷改了cache文件的存储路径规则,改为按照版本号生成,建议改成
def get_cache_path(game_install_path):
from functools import cmp_to_key
def cmp(ver_a: str, ver_b: str):
ver_a = ver_a.split('.')
ver_b = ver_b.split('.')
ver_a = [int(a) for a in ver_a]
ver_b = [int(b) for b in ver_b]
length = min(len(ver_a), len(ver_b))
for i in range(length):
if ver_a[i] != ver_b[i]:
return ver_b[i] - ver_a[i]
return len(ver_b) - len(ver_a)
logger.info('Getting gacha query cache path')
cache_path = os.path.join(
game_install_path,
'StarRail_Data', 'webCaches'
)
maybe_dirs = os.listdir(cache_path)
# 排序,要版本号大的在前
maybe_dirs = sorted(maybe_dirs, key=cmp_to_key(cmp))
cache_path = os.path.join(
cache_path,
maybe_dirs[0],
'Cache',
'Cache_Data',
'data_2'
)
if not os.path.exists(cache_path):
error_msg = (
f'Cache path {cache_path} is not existing. Please visit '
'the gacha querying page before exporting gacha data.'
)
logger.error(error_msg)
return cache_path
关于windows上无法打开被占用文件的问题,建议改成robocopy来复制,get_api_from_cache
建议改成
def get_api_from_cache(cache_path):
def get_api_form_cache_windows(cache_path):
tmpdir_path='{}\\tmp'.format(os.path.abspath('.'))
try:
if os.path.exists(tmpdir_path) and os.path.isfile(tmpdir_path):
tmpdir_path='{}{:0>4d}'.format(tmpdir_path, int(time.time()) % 10000)
os.mkdir(tmpdir_path)
if not os.path.exists(tmpdir_path):
os.mkdir(tmpdir_path)
except BaseException as E:
logger.error('TODO20240413:{}'.format(E))
else:
cmd = 'robocopy "{}" "{}" data_2'.format(os.path.dirname(cache_path), tmpdir_path)
res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
res.wait(5)
assert 0==res.returncode, res.stderr.read()
cache_path='{}\\data_2'.format(tmpdir_path)
logger.info('Creating tmp file ok')
return cache_path
logger.info('Getting api URL from cache')
import os, time, subprocess
if os.name.startswith('nt'):
cache_path = get_api_form_cache_windows(cache_path)
with open(cache_path, 'rb') as f_cache:
cache = f_cache.read()
parts = cache.split(b'1/0/')
parts = [part.split(b'\x00')[0].decode(errors='ignore') for part in parts]
parts = map(get_url_from_text, parts)
parts = list(filter(bool, parts))
if not parts:
error_msg = (
'API URL is not found in cache. Please visit the gacha querying '
'page before exporting gacha data.'
)
logger.error(error_msg)
return ''
return get_latest_url(parts)
在python3.9,崩铁2.22,windows10上测试了以上修改是ok的,希望版本能够更新一下,谢谢,懒得提merge请求了
已经开启过游戏 刷新过 cache2 文件。
下载源码运行
2023-05-12 13:52:08,310 gacha\service.py Line 38 - [INFO] Length of payload.data.list: 0
2023-05-12 13:52:31,049 gacha\service.py Line 77 - [CRITICAL] Error while checking response from api URL, exitting
File "D:\Person\project\per\honkai-starrail-toolkit-develop\honkai-starrail-toolkit-develop\starrail\gacha\service.py", line 78, in export_gacha_from_api
raise ValueError('Invalid or expired api, please check your input')
ValueError: Invalid or expired api, please check your input
定位
def syncGachaData(self):
self.logAndUpdateState(babelfish.ui_extracting_api_url())
api_url = service.detect_api_url()
response, code = service.fetch_json(api_url)
valid = service.check_response(response, code)
网页访问api_url返回
{
"retcode": 0,
"message": "OK",
"data": {
"page": "1",
"size": "5",
"list": [],
"region": "prod_gf_cn",
"region_time_zone": 8
}
}
在 ‘ service.check_response’ 抛异常了
if not payload['data']['list']:
logger.info(
f'Length of payload.data.list: '
f'{len(payload["data"]["list"])}',
)
return False
源码 版本 20230512 12:00 直接下载的develop.zip
gui程序版本 StarRailToolkit-v0.5.4_windows-64bit
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.