-
Notifications
You must be signed in to change notification settings - Fork 481
/
msg.py
111 lines (100 loc) · 3.03 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
# -*- coding: utf-8 -*
'''
项目名称: JD-Script / msg
Author: Curtin
功能:通知服务
Date: 2021/11/7 下午6:46
TG交流 https://t.me/topstyle996
TG频道 https://t.me/TopStyle2021
# 调用方法:
from msg import msg
#启动通知服务
msg().main()
# 发信息 msg打印控制台同时会记录日志在message(),后面统一发送
msg(" Hello ! ")
print(" test ") # 不会记录
msg(" My name is Curtin ")
# 发送到通知服务(如tg机器人、企业微信等)
message = msg().message()
send("标题", message)
'''
import requests
import os, sys
## 获取通知服务
class msg(object):
def __init__(self, m=None):
if m != None:
self.str_msg = m
print(self.str_msg)
self.message()
else:
self.str_msg = None
def message(self):
global msg_info
try:
if self.str_msg:
msg_info = "{}\n{}".format(msg_info, self.str_msg)
except:
if self.str_msg:
msg_info = "{}".format(self.str_msg)
else:
msg_info = ""
sys.stdout.flush()
if msg_info:
return msg_info
else:
return ""
def getsendNotify(self, a=0):
if a == 0:
a += 1
try:
url = 'https://ghproxy.com/https://raw.githubusercontent.com/curtinlv/JD-Script/main/sendNotify.py'
response = requests.get(url)
if 'curtinlv' in response.text:
with open('sendNotify.py', "w+", encoding="utf-8") as f:
f.write(response.text)
else:
if a < 5:
a += 1
return self.getsendNotify(a)
else:
pass
except:
if a < 5:
a += 1
return self.getsendNotify(a)
else:
pass
def main(self):
global send
cur_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(cur_path)
if os.path.exists(cur_path + "/sendNotify.py"):
try:
from sendNotify import send
except:
self.getsendNotify()
try:
from sendNotify import send
except:
print("加载通知服务失败~")
else:
self.getsendNotify()
try:
from sendNotify import send
except:
print("加载通知服务失败~")
if __name__ == '__main__':
# 启动通知服务
msg().main()
# msg打印控制台同时会记录日志在message(),后面统一发送
print("\n打印在控制台的信息:")
msg("Hello ! ")
print("Test ") # 不会记录
msg("My name is Curtin. ")
# 发送到通知服务(如tg机器人、企业微信等)
message = msg().message()
send("标题", message)
print("\n发送到通知服务的信息:")
print(message)