Files
zjk2017-ArcadiaScriptPublic/tianyi/initialize.py
2024-06-26 13:19:25 +08:00

85 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 注释最后一行代码,即可不会有延迟
import logging
import time
import random
import notify
message_list = [] # 存储消息数据
def init_logger():
"""
初始化日志系统
:return:
"""
log = logging.getLogger()
log.setLevel(logging.INFO)
log_format = logging.Formatter(
'%(asctime)s - %(filename)s:%(lineno)d - %(levelname)s: %(message)s'
)
# Console
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(log_format)
log.addHandler(ch)
def info_message(message_content):
"""
成功日志输出
:param message_content:
:return:
"""
logging.info(f"🎈{message_content}")
message(f"🎈{message_content}")
def error_message(message_content):
"""
失败日志输出
:param message_content:
:return:
"""
logging.error(f"😢{message_content}")
message(f"😢{message_content}")
def message(message_content):
"""
日志和消息放在一起
:param message_content:
:return:
"""
message_list.append(message_content)
def send_notify(title):
"""
发送通知
:param title:
:return:
"""
msg = '\n'.join(message_list)
notify.send(title, msg)
def init():
"""
延迟时间和日志初始化
:return:
"""
# 初始化日志
init_logger()
# 随机延迟
logging.info("开启10秒到5分钟之间的随机延迟时间如果不需要延迟 请将initialize.py代码中的最后一行代码注释掉")
delay = int(random.uniform(10, 300))
logging.info(f"开启延迟,{delay}秒后执行代码")
# time.sleep(delay) # 注释该行代码,即可不会有延迟