优化代码

This commit is contained in:
limoruirui
2022-09-11 23:52:45 +08:00
parent 6770477abd
commit 5cf7b55257
4 changed files with 28 additions and 14 deletions

View File

@@ -6,12 +6,14 @@
# -------------------------------
from requests import post
from json import dumps
from sys import path
path.append("./tools")
from tool import get_environ
tg_userId = get_environ("TG_USER_ID")
tgbot_token = get_environ("TG_BOT_TOKEN")
tg_push_api = get_environ("TG_API_HOST")
pushplus_token = get_environ("PUSH_PLUS_TOKEN")
tg_userId = get_environ("TG_USER_ID", "", False)
tgbot_token = get_environ("TG_BOT_TOKEN", "", False)
tg_push_api = get_environ("TG_API_HOST", "", False)
pushplus_token = get_environ("PUSH_PLUS_TOKEN", "", False)
def tgpush(title, content):
url = f"https://api.telegram.org/bot{tgbot_token}/sendMessage"
@@ -37,8 +39,8 @@ def pushplus(title, content):
post(url, headers=headers, data=dumps(data))
except:
print('推送失败')
def push(self, title, content):
def push(title, content):
if pushplus_token != "":
self.pushplus(title, content)
pushplus(title, content)
if tgbot_token != "" and tg_userId != "":
self.tgpush(title, content)
tgpush(title, content)