feat: 修改通知结构;

docs: 修改 BUG ISSUE 模板
This commit is contained in:
shitao 2021-02-25 20:32:33 +08:00
parent 307550db6b
commit ea6dd60864
4 changed files with 98 additions and 76 deletions

View File

@ -1,8 +1,8 @@
---
name: Bug 反馈
name: Bug 反馈
about: 运行 Python 脚本时出现 Bug
title: ''
labels: ''
title: '【脚本名称】具体 BUG'
labels: bug
assignees: ''
---

View File

@ -6,17 +6,8 @@ import time
from datetime import datetime, timedelta
from motto import Motto
from utils.config import checkin_map, get_checkin_info
from utils.message import (
message2bark,
message2coolpush,
message2dingtalk,
message2qmsg,
message2server,
message2server_turbo,
message2telegram,
important_notice,
)
from utils.config import checkin_map, get_checkin_info, get_notice_info
from utils.message import push_message
def main_handler(event, context):
@ -24,19 +15,8 @@ def main_handler(event, context):
utc_time = datetime.utcnow() + timedelta(hours=8)
if "IS_GITHUB_ACTION" in os.environ:
message = os.getenv("ONLY_MESSAGE")
dingtalk_secret = os.getenv("DINGTALK_SECRET")
dingtalk_access_token = os.getenv("DINGTALK_ACCESS_TOKEN")
bark_url = os.getenv("BARK_URL")
sckey = os.getenv("SCKEY")
sendkey = os.getenv("SENDKEY")
tg_bot_token = os.getenv("TG_BOT_TOKEN")
tg_user_id = os.getenv("TG_USER_ID")
qmsg_key = os.getenv("QMSG_KEY")
coolpushskey = os.getenv("COOLPUSHSKEY")
coolpushqq = os.getenv("COOLPUSHQQ")
coolpushwx = os.getenv("COOLPUSHWX")
coolpushemail = os.getenv("COOLPUSHEMAIL")
motto = os.getenv("MOTTO")
notice_info = get_notice_info(data=None)
check_info = get_checkin_info(data=None)
else:
if isinstance(event, dict):
@ -46,19 +26,8 @@ def main_handler(event, context):
try:
with open(os.path.join(os.path.dirname(__file__), "config/config.json"), "r", encoding="utf-8") as f:
data = json.loads(f.read())
dingtalk_secret = data.get("DINGTALK_SECRET")
dingtalk_access_token = data.get("DINGTALK_ACCESS_TOKEN")
bark_url = data.get("BARK_URL")
sckey = data.get("SCKEY")
sendkey = data.get("SENDKEY")
qmsg_key = data.get("QMSG_KEY")
tg_bot_token = data.get("TG_BOT_TOKEN")
tg_user_id = data.get("TG_USER_ID")
coolpushskey = data.get("COOLPUSHSKEY")
coolpushqq = data.get("COOLPUSHQQ")
coolpushwx = data.get("COOLPUSHWX")
coolpushemail = data.get("COOLPUSHEMAIL")
motto = data.get("MOTTO")
notice_info = get_notice_info(data=data)
check_info = get_checkin_info(data=data)
except Exception as e:
raise e
@ -67,8 +36,6 @@ def main_handler(event, context):
if check_info.get("xmly_cookie_list"):
msg_list = checkin_map.get("XMLY_COOKIE_LIST")(xmly_cookie_list=check_info.get("xmly_cookie_list")).main()
content_list += msg_list
elif message == "qqread":
return
else:
for one_check, check_func in checkin_map.items():
if one_check not in ["XMLY_COOKIE_LIST"]:
@ -83,7 +50,6 @@ def main_handler(event, context):
print(e)
msg_list = []
content_list += msg_list
if motto:
try:
msg_list = Motto().main()
@ -91,7 +57,7 @@ def main_handler(event, context):
print(e)
msg_list = []
content_list += msg_list
content_list.append(f"本次任务使用时间: {time.time() - start_time}")
if message == "xmly":
if utc_time.hour in [9, 18] and utc_time.minute == 0:
flag = True
@ -100,38 +66,7 @@ def main_handler(event, context):
else:
flag = True
if flag:
use_time_info = f"本次任务使用时间: {time.time() - start_time}"
content_list.append(use_time_info)
content_str = "\n-----------------------------\n\n".join(content_list)
notice = important_notice()
message_list = [content_str]
if notice:
message_list.append(notice)
content_list.append(notice)
for message in message_list:
if dingtalk_access_token and dingtalk_secret:
message2dingtalk(
dingtalk_secret=dingtalk_secret, dingtalk_access_token=dingtalk_access_token, content=message
)
if sckey:
message2server(sckey=sckey, content=message)
if sendkey:
message2server_turbo(sendkey=sendkey, content=message)
if tg_user_id and tg_bot_token:
message2telegram(tg_user_id=tg_user_id, tg_bot_token=tg_bot_token, content=message)
if bark_url:
message2bark(bark_url=bark_url, content=message)
for content in content_list:
if qmsg_key:
message2qmsg(qmsg_key=qmsg_key, content=content)
if coolpushskey:
message2coolpush(
coolpushskey=coolpushskey,
content=content,
coolpushqq=coolpushqq,
coolpushwx=coolpushwx,
coolpushemail=coolpushemail,
)
push_message(content_list=content_list, notice_info=notice_info)
return

View File

@ -50,8 +50,23 @@ checkin_map = {
"XMLY_COOKIE_LIST": XMLYCheckIn,
}
notice_map = {
"DINGTALK_SECRET": "",
"DINGTALK_ACCESS_TOKEN": "",
"BARK_URL": "",
"SCKEY": "",
"SENDKEY": "",
"TG_BOT_TOKEN": "",
"TG_USER_ID": "",
"QMSG_KEY": "",
"COOLPUSHSKEY": "",
"COOLPUSHQQ": "",
"COOLPUSHWX": "",
"COOLPUSHEMAIL": "",
}
def env2json(key):
def env2list(key):
try:
value = json.loads(os.getenv(key, [])) if os.getenv(key) else []
if isinstance(value, list):
@ -64,6 +79,19 @@ def env2json(key):
return value
def env2str(key):
try:
value = json.loads(os.getenv(key, "")) if os.getenv(key) else ""
if isinstance(value, list):
value = value
else:
value = None
except Exception as e:
print(e)
value = None
return value
def get_checkin_info(data):
result = {}
if isinstance(data, dict):
@ -71,5 +99,16 @@ def get_checkin_info(data):
result[one.lower()] = data.get(one, [])
else:
for one in checkin_map.keys():
result[one.lower()] = env2json(one)
result[one.lower()] = env2list(one)
return result
def get_notice_info(data):
result = {}
if isinstance(data, dict):
for one in notice_map.keys():
result[one.lower()] = data.get(one, None)
else:
for one in notice_map.keys():
result[one.lower()] = env2list(one)
return result

View File

@ -93,5 +93,53 @@ def important_notice():
return notice
def push_message(content_list: list, notice_info: dict):
dingtalk_secret = notice_info.get("dingtalk_secret")
dingtalk_access_token = notice_info.get("dingtalk_access_token")
bark_url = notice_info.get("bark_url")
sckey = notice_info.get("sckey")
sendkey = notice_info.get("sendkey")
qmsg_key = notice_info.get("qmsg_key")
tg_bot_token = notice_info.get("tg_bot_token")
tg_user_id = notice_info.get("tg_user_id")
coolpushskey = notice_info.get("coolpushskey")
coolpushqq = notice_info.get("coolpushqq")
coolpushwx = notice_info.get("coolpushwx")
coolpushemail = notice_info.get("coolpushemail")
content_str = "\n-----------------------------\n\n".join(content_list)
message_list = [content_str]
try:
notice = important_notice()
if notice:
message_list.append(notice)
content_list.append(notice)
except Exception as e:
print("获取重要通知失败:", e)
for message in message_list:
if dingtalk_access_token and dingtalk_secret:
message2dingtalk(
dingtalk_secret=dingtalk_secret, dingtalk_access_token=dingtalk_access_token, content=message
)
if sckey:
message2server(sckey=sckey, content=message)
if sendkey:
message2server_turbo(sendkey=sendkey, content=message)
if tg_user_id and tg_bot_token:
message2telegram(tg_user_id=tg_user_id, tg_bot_token=tg_bot_token, content=message)
if bark_url:
message2bark(bark_url=bark_url, content=message)
for content in content_list:
if qmsg_key:
message2qmsg(qmsg_key=qmsg_key, content=content)
if coolpushskey:
message2coolpush(
coolpushskey=coolpushskey,
content=content,
coolpushqq=coolpushqq,
coolpushwx=coolpushwx,
coolpushemail=coolpushemail,
)
if __name__ == '__main__':
print(important_notice())