-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_tencentcloud_Lighthouse_sdk.py
71 lines (65 loc) · 2.37 KB
/
update_tencentcloud_Lighthouse_sdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import subprocess
import time
import requests
qmsgurl = '' #qmsg酱私有云url地址:例:https://qmsg.zendee.cn,私有云架设教程:https://qmsg.zendee.cn/docs/plus/
qkey = '' # Qmsg酱QQ推送key(不懂不要填,可空)
bot = ''
qq = '' # 需要推送的qq号或群号 (不懂不要填,可空)
# 获取最新SDK版本号
def get_latest_sdk_version():
url = "https://pypi.org/pypi/tencentcloud-sdk-python-lighthouse/json"
response = requests.get(url)
data = response.json()
latest_version = data["info"]["version"]
return latest_version
# 检测当前SDK版本号
def get_current_sdk_version():
version_file = open("version.txt", "r")
current_version = version_file.read().strip()
version_file.close()
return current_version
# 更新SDK包
def update_sdk(version):
pip_command = f"/www/server/panel/pyenv/bin/pip3 install --upgrade tencentcloud-sdk-python-lighthouse"
subprocess.run(pip_command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# 将 stdout 和 stderr 重定向到 /dev/null
with open(os.devnull, 'w') as fnull:
subprocess.run(["tee", "/dev/null"], stdin=subprocess.PIPE)
# QMSG酱推送
def qmsg_send(msg):
global qmsgurl, qkey, qq, bot
if qmsgurl == '':
qmsgurl = 'https://qmsg.zendee.cn'
if qkey == '':
return
qmsg_url = str(qmsgurl) + "/send/" + str(qkey)
#qmsg_url = str(qmsgurl) + "/group/" + str(qkey)
data = {
'qq': f'{qq}',
'bot': f'{bot}',
'msg': msg
}
requests.post(qmsg_url, data = data)
# 检测并更新SDK
def main():
current_version = get_current_sdk_version()
latest_version = get_latest_sdk_version()
if current_version != latest_version:
msg = f"检测到腾讯轻量云SDK有更新\n当前版本:{current_version}\n最新版本:{latest_version}"
#qmsg_send(msg)
print(msg)
update_sdk(latest_version)
msg = "更新完成!"
print(msg)
with open("version.txt", "w") as version_file:
version_file.write(latest_version)
# 发送qmsg酱推送通知消息
msg = f"腾讯轻量云SDK已成功更新到版本:{latest_version}"
#qmsg_send(msg)
print(msg)
else:
msg = "当前已经是最新版本!"
print(msg)
if __name__ == "__main__":
main()