2020-12-06 11:17:31 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
2020-12-10 12:24:40 +08:00
|
|
|
import os
|
2020-12-12 08:42:52 +08:00
|
|
|
import sys
|
2020-12-07 13:29:36 +08:00
|
|
|
import time
|
2020-12-09 17:05:09 +08:00
|
|
|
from datetime import datetime, timedelta
|
2020-12-07 13:29:36 +08:00
|
|
|
|
2020-12-21 21:08:22 +08:00
|
|
|
from motto import Motto
|
2021-02-25 20:32:33 +08:00
|
|
|
from utils.config import checkin_map, get_checkin_info, get_notice_info
|
|
|
|
from utils.message import push_message
|
2020-12-07 13:29:36 +08:00
|
|
|
|
|
|
|
|
2020-12-06 11:17:31 +08:00
|
|
|
def main_handler(event, context):
|
2020-12-10 12:34:33 +08:00
|
|
|
start_time = time.time()
|
|
|
|
utc_time = datetime.utcnow() + timedelta(hours=8)
|
2020-12-10 12:24:40 +08:00
|
|
|
if "IS_GITHUB_ACTION" in os.environ:
|
2020-12-22 09:42:46 +08:00
|
|
|
message = os.getenv("ONLY_MESSAGE")
|
|
|
|
motto = os.getenv("MOTTO")
|
2021-02-25 20:32:33 +08:00
|
|
|
notice_info = get_notice_info(data=None)
|
2021-01-10 10:13:19 +08:00
|
|
|
check_info = get_checkin_info(data=None)
|
2020-12-08 13:31:25 +08:00
|
|
|
else:
|
2020-12-10 12:24:40 +08:00
|
|
|
if isinstance(event, dict):
|
|
|
|
message = event.get("Message")
|
|
|
|
else:
|
|
|
|
message = None
|
2021-01-12 07:03:34 +08:00
|
|
|
try:
|
2021-02-23 22:46:29 +08:00
|
|
|
with open(os.path.join(os.path.dirname(__file__), "config/config.json"), "r", encoding="utf-8") as f:
|
2021-01-12 07:03:34 +08:00
|
|
|
data = json.loads(f.read())
|
|
|
|
motto = data.get("MOTTO")
|
2021-02-25 20:32:33 +08:00
|
|
|
notice_info = get_notice_info(data=data)
|
2021-01-12 07:03:34 +08:00
|
|
|
check_info = get_checkin_info(data=data)
|
|
|
|
except Exception as e:
|
|
|
|
raise e
|
2020-12-10 12:45:24 +08:00
|
|
|
content_list = [f"当前时间: {utc_time}"]
|
2020-12-10 17:08:36 +08:00
|
|
|
if message == "xmly":
|
2021-01-10 10:13:19 +08:00
|
|
|
if check_info.get("xmly_cookie_list"):
|
2021-03-05 01:04:02 +08:00
|
|
|
check_name, check_func = checkin_map.get("XMLY_COOKIE_LIST")
|
|
|
|
for check_item in check_info.get("xmly_cookie_list", []):
|
2021-01-11 18:05:04 +08:00
|
|
|
try:
|
2021-03-05 01:04:02 +08:00
|
|
|
msg = check_func(check_item).main()
|
|
|
|
content_list.append(f"【{check_name}】\n{msg}")
|
2021-01-11 18:05:04 +08:00
|
|
|
except Exception as e:
|
2021-03-05 01:04:02 +08:00
|
|
|
print(check_name, e)
|
|
|
|
else:
|
|
|
|
for one_check, check_tuple in checkin_map.items():
|
|
|
|
check_name, check_func = check_tuple
|
|
|
|
if one_check not in ["XMLY_COOKIE_LIST"]:
|
|
|
|
if check_info.get(one_check.lower()):
|
|
|
|
print(f"----------已检测到正确的配置,并开始执行 {one_check} 签到----------")
|
|
|
|
for check_item in check_info.get(one_check.lower(), []):
|
|
|
|
try:
|
|
|
|
msg = check_func(check_item).main()
|
|
|
|
content_list.append(f"【{check_name}】\n{msg}")
|
|
|
|
except Exception as e:
|
|
|
|
print(check_name, e)
|
|
|
|
else:
|
|
|
|
print(f"----------未检测到正确的配置,并跳过执行 {one_check} 签到----------")
|
2020-12-08 13:31:25 +08:00
|
|
|
if motto:
|
2021-01-10 10:13:19 +08:00
|
|
|
try:
|
|
|
|
msg_list = Motto().main()
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
msg_list = []
|
2020-12-08 13:31:25 +08:00
|
|
|
content_list += msg_list
|
2021-03-04 12:31:06 +08:00
|
|
|
content_list.append(f"任务使用时间: {int(time.time() - start_time)} 秒")
|
2020-12-09 17:05:09 +08:00
|
|
|
if message == "xmly":
|
|
|
|
if utc_time.hour in [9, 18] and utc_time.minute == 0:
|
|
|
|
flag = True
|
|
|
|
else:
|
|
|
|
flag = False
|
|
|
|
else:
|
|
|
|
flag = True
|
|
|
|
if flag:
|
2021-02-25 20:32:33 +08:00
|
|
|
push_message(content_list=content_list, notice_info=notice_info)
|
2020-12-06 11:17:31 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
|
2020-12-07 13:29:36 +08:00
|
|
|
if __name__ == "__main__":
|
2020-12-12 08:42:52 +08:00
|
|
|
args = sys.argv
|
|
|
|
if len(args) > 1:
|
2020-12-22 09:42:46 +08:00
|
|
|
event = {"Message": args[1]}
|
2020-12-12 08:42:52 +08:00
|
|
|
else:
|
|
|
|
event = None
|
|
|
|
main_handler(event=event, context=None)
|