Finally Deprecate Analytics & Added timeout to script to avoid exceed in Action #8

This commit is contained in:
GamerNoTitle 2023-04-01 14:29:07 +08:00
parent d2649c36b0
commit fab44781ca

23
main.py
View File

@ -31,7 +31,7 @@ class RunError(Exception):
token = config['token']
client_type = config['type']
try:
ver_info = r.get('https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?key=eYd89JmJ&launcher_id=18').text
ver_info = r.get('https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?key=eYd89JmJ&launcher_id=18', timeout=60).text
version = json.loads(ver_info)['data']['game']['latest']['version']
print(f'从官方API获取到云·原神最新版本号{version}')
except:
@ -41,7 +41,6 @@ deviceid = config['deviceid']
devicename = config['devicename']
devicemodel = config['devicemodel']
appid = config['appid']
analytics = config['analytics']
bbsid = re.findall(r'oi=[0-9]+', token)[0].replace('oi=', '')
@ -73,32 +72,18 @@ if __name__ == '__main__':
else:
if token == '' or android == 0 or deviceid == '' or devicemodel == '' or appid == 0:
raise RunError(f'请确认您的配置文件配置正确再运行本程序!')
if analytics:
try:
# Disable SSL warning of analytics server
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
ana = r.get(
f'https://analytics.api.ninym.top/mhyy?type={client_type}&version={version}&android={android}&deviceid={deviceid}&devicename={devicename}&devicemodel={devicemodel}&appid={appid}&bbsid={bbsid}', verify=False)
if json.loads(ana.text)['msg'] == 'OK':
print('统计信息提交成功,感谢你的支持!')
elif json.loads(ana.text)['msg'] == 'Duplicated':
print('你的统计信息已经提交过啦!感谢你的支持!')
else:
print(f'[WARN] 统计信息提交错误:{ana.text}')
except Exception as e:
print(f'提交失败!{e}')
wait_time = random.randint(1, 3600) # Random Sleep to Avoid Ban
print(f'为了避免同一时间签到人数太多导致被官方怀疑,开始休眠 {wait_time}')
time.sleep(wait_time)
wallet = r.get(WalletURL, headers=headers)
wallet = r.get(WalletURL, headers=headers, timeout=60)
if wallet.text == {"data": None,"message":"登录已失效,请重新登录","retcode":-100}:
print(f'当前登录已过期,请重新登陆!返回为:{wallet.text}')
else:
print(
f"你当前拥有免费时长 {json.loads(wallet.text)['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {json.loads(wallet.text)['data']['play_card']['short_msg']},拥有米云币 {json.loads(wallet.text)['data']['coin']['coin_num']}")
announcement = r.get(AnnouncementURL, headers=headers)
announcement = r.get(AnnouncementURL, headers=headers, timeout=60)
print(f'获取到公告列表:{json.loads(announcement.text)["data"]}')
res = r.get(NotificationURL, headers=headers)
res = r.get(NotificationURL, headers=headers, timeout=60)
success,Signed = False,False
try:
if list(json.loads(res.text)['data']['list']) == []: