-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg.py
83 lines (63 loc) · 1.62 KB
/
msg.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
72
73
74
75
76
77
78
79
80
81
82
83
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分钟之间的随机延迟时间,如果不需要延迟 请将 msg.py 代码中的最后一行代码注释掉")
delay = int(random.uniform(10, 300))
logging.info(f"开启延迟,{delay}秒后执行代码")
time.sleep(delay) # 注释该行代码,即可不会有延迟