mirror of
https://github.com/CHERWING/CHERWIN_SCRIPTS.git
synced 2024-11-22 09:04:11 +08:00
Update CHERWIN_TOOLS.py
This commit is contained in:
parent
6b348043d0
commit
debc6f1596
@ -9,6 +9,8 @@ from http import HTTPStatus
|
||||
NOW_TOOLS_VERSION = '2024.05.04'
|
||||
if os.path.isfile('DEV_ENV.py'):
|
||||
import DEV_ENV
|
||||
|
||||
|
||||
# 尝试导入包
|
||||
def import_or_install(package_name, import_name=None):
|
||||
# 如果传入了 import_name,则使用它来检查模块,否则默认与包名相同
|
||||
@ -37,6 +39,7 @@ def import_or_install(package_name, import_name=None):
|
||||
except Exception as e:
|
||||
print(f"处理 {package_name} 模块时发生错误. 错误信息: {e}")
|
||||
|
||||
|
||||
def SAVE_INVITE_CODE(file_name, new_data):
|
||||
# 读取现有JSON文件(如果存在)
|
||||
try:
|
||||
@ -62,6 +65,7 @@ def SAVE_INVITE_CODE(file_name, new_data):
|
||||
with open(file_name, 'w', encoding='utf-8') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
|
||||
# 将参数转换为字典
|
||||
def create_dict_from_string(self, data_string):
|
||||
params = {}
|
||||
@ -71,6 +75,7 @@ def create_dict_from_string(self, data_string):
|
||||
params[key] = value
|
||||
return params
|
||||
|
||||
|
||||
def compare_versions(local_version, server_version):
|
||||
local_parts = local_version.split('.') # 将本地版本号拆分成数字部分
|
||||
server_parts = server_version.split('.') # 将服务器版本号拆分成数字部分
|
||||
@ -87,6 +92,7 @@ def compare_versions(local_version, server_version):
|
||||
else:
|
||||
return False # 当前版本与服务器版本相同或更高
|
||||
|
||||
|
||||
def CHECK_UPDATE(local_version, server_version_url, server_script_url, script_filename):
|
||||
"""
|
||||
检查版本并更新
|
||||
@ -141,7 +147,9 @@ def CHECK_UPDATE(local_version, server_version_url, server_script_url, script_fi
|
||||
|
||||
return False # 返回 False 表示没有进行更新操作
|
||||
|
||||
def CHECK_UPDATE_NEW(local_version, server_version, server_script_url, script_filename,server_version_url=None,APP_NAME=None):
|
||||
|
||||
def CHECK_UPDATE_NEW(local_version, server_version, server_script_url, script_filename, server_version_url=None,
|
||||
APP_NAME=None):
|
||||
"""
|
||||
检查版本并更新
|
||||
|
||||
@ -196,6 +204,7 @@ def CHECK_UPDATE_NEW(local_version, server_version, server_script_url, script_fi
|
||||
|
||||
return False # 返回 False 表示没有进行更新操作
|
||||
|
||||
|
||||
def down_file(filename, file_url):
|
||||
print(f'开始下载:{filename},下载地址:{file_url}')
|
||||
try:
|
||||
@ -221,6 +230,8 @@ def down_file(filename, file_url):
|
||||
except Exception as e:
|
||||
print(f'【{filename}】下载失败:{str(e)}')
|
||||
return False
|
||||
|
||||
|
||||
def get_AuthorInviteCode(url):
|
||||
global AuthorCode
|
||||
try:
|
||||
@ -268,6 +279,7 @@ def GET_TIPS(server_base_url):
|
||||
***********通知内容************\n
|
||||
''')
|
||||
|
||||
|
||||
def CHECK_PARAMENTERS(index, input_string, required_parameters):
|
||||
# required_parameters = ['deviceid', 'jysessionid', 'shopid', 'memberid', 'access_token', 'sign']
|
||||
|
||||
@ -322,6 +334,7 @@ def QIANWEN(tongyiSysPromt, content, api_key):
|
||||
else:
|
||||
print('dashscope 模块无法导入,函数无法执行。')
|
||||
|
||||
|
||||
# 取环境变量,并分割
|
||||
def ENV_SPLIT(input_str):
|
||||
parts = []
|
||||
@ -346,6 +359,7 @@ def ENV_SPLIT(input_str):
|
||||
# print([out_str])
|
||||
return ([out_str])
|
||||
|
||||
|
||||
# 使用导入的模块进行验证码识别
|
||||
def CAPCODE(captcha_slider, captcha_bg):
|
||||
ddddocr = import_or_install('ddddocr')
|
||||
@ -363,6 +377,7 @@ def CAPCODE(captcha_slider, captcha_bg):
|
||||
print('ddddocr 模块无法导入,函数无法执行。')
|
||||
return False
|
||||
|
||||
|
||||
def BASE64_TO_IMG(base64_string, output_path):
|
||||
import base64
|
||||
import io
|
||||
@ -386,6 +401,7 @@ def BASE64_TO_IMG(base64_string, output_path):
|
||||
print('需要的模块[PIL]无法导入,函数无法执行。')
|
||||
return False
|
||||
|
||||
|
||||
def send_wxpusher(UID, one_msg, APP_NAME, help=False):
|
||||
WXPUSHER = os.environ.get('WXPUSHER', False)
|
||||
if WXPUSHER:
|
||||
@ -429,16 +445,18 @@ def wxpusher(UID,msg,title,help=False):
|
||||
except Exception as e:
|
||||
return f"发生意外错误:{str(e)}"
|
||||
|
||||
|
||||
def RESTART_SCRIPT(RESTART_SCRIPT_NAME):
|
||||
python = sys.executable
|
||||
os.execl(python, RESTART_SCRIPT_NAME, *sys.argv[1:])
|
||||
|
||||
|
||||
def CHECK():
|
||||
global CHERWIN_SCRIPT_CONFIG
|
||||
print('>>>>>>>开始获取版本信息...')
|
||||
baseurl = 'https://py.cherwin.cn/'
|
||||
TOOLS_NAME = 'CHERWIN_TOOLS.py'
|
||||
server_script_url = f'{baseurl}{TOOLS_NAME}'
|
||||
server_script_url = f'https://github.com/CHERWING/CHERWIN_SCRIPTS/raw/main/{TOOLS_NAME}'
|
||||
try:
|
||||
response = requests.get(f'{baseurl}CHERWIN_SCRIPT_CONFIG.json', verify=False)
|
||||
response.encoding = 'utf-8'
|
||||
@ -458,7 +476,6 @@ def CHECK():
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def main(APP_NAME, local_script_name, ENV_NAME, local_version):
|
||||
global APP_INFO, TIPS, TIPS_HTML
|
||||
git_url = f'https://github.com/CHERWING/CHERWIN_SCRIPTS/raw/main/{local_script_name}'
|
||||
@ -474,7 +491,8 @@ def main(APP_NAME,local_script_name,ENV_NAME,local_version):
|
||||
exit()
|
||||
TIPS = APP_INFO.get('NTC', '') if APP_INFO.get('NTC', '') else CHERWIN_SCRIPT_CONFIG.get('GLOBAL_NTC', '')
|
||||
|
||||
TIPS_HTML = APP_INFO.get('NTC', '') if APP_INFO.get('NTC', '') else CHERWIN_SCRIPT_CONFIG.get('GLOBAL_NTC_HTML','')
|
||||
TIPS_HTML = APP_INFO.get('NTC', '') if APP_INFO.get('NTC', '') else CHERWIN_SCRIPT_CONFIG.get('GLOBAL_NTC_HTML',
|
||||
'')
|
||||
ENV = os.environ.get(ENV_NAME)
|
||||
AuthorCode = get_AuthorInviteCode(f'https://yhsh.ziyuand.cn/{ENV_NAME}_INVITE_CODE.json')
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user