-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
154 lines (146 loc) · 5.44 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import threading
import os
from time import sleep
import traceback
from config import global_config as config
from logger import logger, output_list, cnt
from query_weibo import query_weibodynamic, query_valid, USER_NAME_DICT
from query_bili import query_bilidynamic, query_live_status_batch, DYNAMIC_NAME_DICT, LIVE_NAME_DICT, try_cookies
from colorama import Fore, init
from push import notify
def weibo():
prefix = '【查询微博状态】'
enable_dynamic_push = config.get_raw(
'weibo', 'enable_dynamic_push')
cookies_check = config.get_raw(
'weibo', 'enable_cookies_check')
if enable_dynamic_push != 'true':
logger.warning('未开启微博推送功能', prefix)
return
if cookies_check == 'true':
check_uid = config.get_raw(
'weibo', 'cookies_check_uid')
global cnt
cnt += 1
logger.info('开始检测微博', prefix, Fore.GREEN)
test = 0
while True:
intervals_second = float(
config.get_raw('weibo', 'intervals_second'))
if cookies_check == 'true' and not query_valid(check_uid, config.WeiboCookies):
test += 1
if test == 5:
logger.warning('微博Cookies无效', prefix)
notify("微博Cookies无效", "", on_click='https://m.weibo.cn/')
else:
test = 0
uid_list = config.get_raw('weibo', 'uid_list')
if uid_list:
uid_list = set(uid_list.split(','))
for uid in uid_list:
try:
query_weibodynamic(
uid, config.WeiboCookies, msg)
except BaseException as e:
logger.error(
f'【{uid}】出错【{e}】:{traceback.format_exc()}', prefix)
sleep(max(1, intervals_second))
else:
logger.warning('未填写UID', prefix)
return
if not swi[1]:
swi[1] = 1
logger.info(f'监控列表({len(USER_NAME_DICT)}):{",".join(USER_NAME_DICT.values())}',
prefix, Fore.LIGHTYELLOW_EX)
def bili_dy():
prefix = '【查询动态状态】'
enable_dynamic_push = config.get_raw(
'bili', 'enable_dynamic_push')
if enable_dynamic_push != 'true':
logger.warning('未开启动态推送功能', prefix)
return
global cnt
cnt += 1
logger.info('开始检测动态', prefix, Fore.GREEN)
test = 0
while True:
intervals_second = float(config.get_raw(
'bili', 'dynamic_intervals_second'))
if not try_cookies(config.BiliCookies):
test += 1
if test == 5:
logger.warning('B站Cookies无效', prefix)
notify("B站Cookies无效", "", on_click='https://www.bilibili.com/')
else:
test = 0
uid_list = config.get_raw('bili', 'dynamic_uid_list')
if uid_list:
uid_list = set(uid_list.split(','))
for uid in uid_list:
try:
query_bilidynamic(uid, config.BiliCookies, msg)
except BaseException as e:
logger.error(
f'【{uid}】出错【{e}】:{traceback.format_exc()}', prefix)
sleep(max(1, intervals_second))
else:
logger.warning('未填写UID', prefix)
return
if not swi[0]:
swi[0] = 1
logger.info(f'监控列表({len(DYNAMIC_NAME_DICT)}):{",".join(DYNAMIC_NAME_DICT.values())}',
prefix, Fore.LIGHTBLUE_EX)
def bili_live():
prefix = '【查询直播状态】'
enable_living_push = config.get_raw('bili', 'enable_living_push')
if enable_living_push != 'true':
logger.warning('未开启直播推送功能', prefix)
return
global cnt
cnt += 1
logger.info('开始检测直播', prefix, Fore.GREEN)
while True:
intervals_second = int(config.get_raw(
'bili', 'live_intervals_second'))
uid_list = config.get_raw('bili', 'live_uid_list')
special = config.get_raw('bili', 'special_list')
if special:
special = set(special.split(','))
else:
special = set()
if uid_list:
uid_list = set(uid_list.split(','))
try:
query_live_status_batch(
uid_list, config.BiliCookies, msg, special)
except BaseException as e:
logger.error(
f'出错【{e}】:{traceback.format_exc()}', prefix)
else:
logger.warning('未填写UID', prefix)
return
if not swi[2]:
swi[2] = 1
logger.info(f'监控列表({len(LIVE_NAME_DICT)}):{",".join(LIVE_NAME_DICT.values())}',
prefix, Fore.CYAN)
sleep(intervals_second)
if __name__ == '__main__':
if not os.path.exists('icon/cover'):
os.makedirs('icon/cover')
if not os.path.exists('icon/opus'):
os.makedirs('icon/opus')
msg = [""]*3
swi = [0]*3
init(autoreset=True)
thread1 = threading.Thread(target=bili_dy, daemon=True)
thread2 = threading.Thread(target=bili_live, daemon=True)
thread3 = threading.Thread(target=weibo, daemon=True)
thread1.start()
thread2.start()
thread3.start()
while True:
if sum(swi) == cnt:
for i in range(3):
if msg[i]:
output_list[i] = msg[i]
sleep(0.1)