2021-09-07 01:07:31 +00:00
|
|
|
import os
|
2021-09-06 21:52:48 +00:00
|
|
|
import time
|
|
|
|
import platform
|
|
|
|
|
|
|
|
from hashlib import md5
|
2021-09-14 08:57:21 +00:00
|
|
|
|
|
|
|
import dotenv
|
2021-09-06 21:52:48 +00:00
|
|
|
from dotenv import dotenv_values
|
|
|
|
from urllib.request import getproxies
|
|
|
|
|
|
|
|
|
2021-09-07 01:07:31 +00:00
|
|
|
logs = ''
|
|
|
|
|
|
|
|
|
2021-09-06 21:52:48 +00:00
|
|
|
def md5_crypto(passwd: str) -> str:
|
|
|
|
return md5(passwd.encode('utf8')).hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
def show_info(tip, info):
|
|
|
|
return "{}: {}".format(tip, info)
|
|
|
|
|
|
|
|
|
|
|
|
def system_info():
|
|
|
|
w_log(show_info("系统及版本信息", platform.platform()))
|
|
|
|
w_log(show_info('系统版本号', platform.version()))
|
|
|
|
w_log(show_info('系统名称', platform.system()))
|
|
|
|
w_log(show_info('系统位数', platform.architecture()))
|
|
|
|
w_log(show_info('计算机类型', platform.machine()))
|
|
|
|
w_log(show_info('处理器类型', platform.processor()))
|
|
|
|
w_log(show_info('Python版本', str(platform.python_version()) + ' ' + str(platform.python_build())))
|
|
|
|
if getproxies():
|
|
|
|
w_log(show_info('系统代理', getproxies()))
|
|
|
|
|
|
|
|
|
|
|
|
def get_config() -> dict:
|
2021-09-14 08:57:21 +00:00
|
|
|
config_path = dotenv.find_dotenv(filename='config.env')
|
|
|
|
w_log('正在使用 ' + config_path + ' 作为配置文件')
|
|
|
|
config = dotenv.dotenv_values(config_path)
|
|
|
|
if not config:
|
|
|
|
w_log('配置文件未配置,请编辑项目目录的.env文件。如文件不存在请自行创建')
|
|
|
|
exit(1)
|
2021-09-06 21:52:48 +00:00
|
|
|
passwd = config.get('MI_PASSWORD')
|
|
|
|
if len(passwd) != 32:
|
|
|
|
config['MI_PASSWORD'] = md5_crypto(passwd)
|
|
|
|
if config.get('SIGN_IN').upper() in ('Y', 'YES'):
|
|
|
|
config['SIGN_IN'] = True
|
2021-09-11 15:29:25 +00:00
|
|
|
else:
|
|
|
|
config['SIGN_IN'] = False
|
2021-10-26 16:35:08 +00:00
|
|
|
if config.get('ENHANCED_MODE').upper() in ('Y', 'YES'):
|
|
|
|
config['ENHANCED_MODE'] = True
|
|
|
|
else:
|
|
|
|
config['ENHANCED_MODE'] = False
|
2021-09-06 21:52:48 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def w_log(text):
|
2021-09-07 01:07:31 +00:00
|
|
|
global logs
|
2021-09-06 21:52:48 +00:00
|
|
|
now_localtime = time.strftime("%H:%M:%S", time.localtime())
|
2021-09-07 01:07:31 +00:00
|
|
|
logs += now_localtime + ' | ' + str(text) + '\n'
|
2021-09-06 21:52:48 +00:00
|
|
|
print(now_localtime + ' | ' + str(text))
|
|
|
|
|
|
|
|
|
2021-09-07 01:07:31 +00:00
|
|
|
def s_log():
|
|
|
|
logs_save= get_config().get('LOG_SAVE')
|
|
|
|
if logs_save == 'Y':
|
|
|
|
global logs
|
|
|
|
folder = os.path.exists('./logs')
|
|
|
|
if not folder:
|
|
|
|
os.makedirs('./logs')
|
|
|
|
now_localtime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
|
fname = now_localtime + '.log'
|
|
|
|
with open('./logs/' + fname, 'a+', encoding='utf-8') as f:
|
|
|
|
f.write(logs)
|
|
|
|
|
|
|
|
|
2021-09-06 21:52:48 +00:00
|
|
|
def conf_check(config: dict):
|
|
|
|
if not config.get('MI_ID'):
|
|
|
|
w_log('小米账户 ID 未配置')
|
2021-09-07 01:07:31 +00:00
|
|
|
return False
|
2021-09-06 21:52:48 +00:00
|
|
|
if not config.get('MI_PASSWORD'):
|
|
|
|
w_log('小米账户 密码 / MD5 未配置')
|
2021-09-07 01:07:31 +00:00
|
|
|
return False
|
2021-09-06 21:52:48 +00:00
|
|
|
if not config.get('USER_AGENT'):
|
|
|
|
w_log('User-Agent 未配置')
|
2021-09-07 01:07:31 +00:00
|
|
|
return False
|
2021-09-06 21:52:48 +00:00
|
|
|
if not config.get('BOARD_ID'):
|
|
|
|
w_log('测试类型 ID 未配置')
|
2021-09-07 01:07:31 +00:00
|
|
|
return False
|
2021-09-14 08:57:21 +00:00
|
|
|
w_log('config.env 已配置')
|
2021-09-07 01:07:31 +00:00
|
|
|
return True
|