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)
get_cache_path
函数,米哈游偷偷改了cache文件的存储路径规则,改为按照版本号生成,建议改成关于windows上无法打开被占用文件的问题,建议改成robocopy来复制,
get_api_from_cache
建议改成在python3.9,崩铁2.22,windows10上测试了以上修改是ok的,希望版本能够更新一下,谢谢,懒得提merge请求了