Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit 6faf4db

Browse files
author
nico
committed
printer重构,实现debug
1 parent 7a42954 commit 6faf4db

File tree

5 files changed

+111
-28
lines changed

5 files changed

+111
-28
lines changed

bilibiliCilent.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ async def parseDanMu(self, messages):
154154

155155
if cmd == 'DANMU_MSG':
156156
# print(dic)
157-
# self.printer.print_danmu_msg(dic)
157+
self.printer.printlist_append(['danmu', '弹幕', 'user', dic])
158158
pass
159159
if cmd == 'SYS_GIFT':
160160
if 'giftId' in dic.keys():
161161

162162
if str(dic['giftId']) in self.bilibili.giftids_raffle.keys():
163-
print(self.bilibili.giftids_raffle[str(dic['giftId'])])
163+
self.printer.printlist_append(['join_lottery', '活动名称', 'user', self.bilibili.giftids_raffle[str(dic['giftId'])]])
164164
headers = {
165165
'Accept': 'application/json, text/plain, */*',
166166
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
@@ -175,10 +175,10 @@ async def parseDanMu(self, messages):
175175
self.api.post_watching_history(self.bilibili.csrf,text1)
176176
result = self.api.check_room_true(text1)
177177
if True in result:
178-
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),"WARNING:检测到房间",str(text1).center(9),"的钓鱼操作")
178+
self.printer.printlist_append(['join_lottery', '钓鱼提醒', 'user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),"WARNING:检测到房间",str(text1).center(9),"的钓鱼操作"])
179179
else:
180180
url = 'http://api.live.bilibili.com/activity/v1/Raffle/check?roomid=' + str(text1)
181-
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(text1).center(9), "的活动抽奖")
181+
self.printer.printlist_append(['join_lottery','','user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(text1).center(9), "的活动抽奖"])
182182
response = requests.get(url, headers=headers)
183183
checklen = response.json()['data']
184184
num = len(checklen)
@@ -188,7 +188,7 @@ async def parseDanMu(self, messages):
188188
resttime = response.json()['data'][j]['time']
189189
raffleid = response.json()['data'][j]['raffleId']
190190
if raffleid not in self.bilibili.activity_raffleid_list:
191-
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(text1).center(9), "的活动抽奖")
191+
self.printer.printlist_append(['join_lottery','','user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(text1).center(9), "的活动抽奖"])
192192
self.bilibili.activity_raffleid_list.append(raffleid)
193193
self.bilibili.activity_roomid_list.append(text1)
194194
self.bilibili.activity_time_list.append(resttime)
@@ -211,24 +211,22 @@ async def parseDanMu(self, messages):
211211
response1 = requests.get(true_url,params=params, headers=headers)
212212
pc_response = requests.get(pc_url, headers=headers)
213213
try:
214-
print("# 移动端活动抽奖结果:", response1.json()['data']['gift_desc'])
214+
self.printer.printlist_append(['join_lottery','','user', "# 移动端活动抽奖结果:", response1.json()['data']['gift_desc']])
215215
except:
216216
pass
217217
try:
218-
print("# 网页端活动抽奖状态:", pc_response.json()['message'])
218+
self.printer.printlist_append(['join_lottery','','user', "# 网页端活动抽奖状态:", pc_response.json()['message']])
219219
except:
220220
pass
221221
break
222222
elif dic['giftId'] == 39:
223-
print("节奏风暴")
223+
self.printer.printlist_append(['join_lottery','','user', "节奏风暴"])
224224
self.get_prensent_of_storm(dic)
225225
else:
226-
print(dic)
227-
print("请联系开发者")
226+
self.printer.printlist_append(['join_lottery','','debug', [dic, "请联系开发者"]])
228227
else:
229-
#print("礼物提示")
230-
# print(dic["msg_text"])
231-
pass
228+
self.printer.printlist_append(['join_lottery','普通送礼提示','user', ['普通送礼提示', dic['msg_text']]])
229+
#self.printer.printlist_append(['join_lottery','','debug', [dic, "请联系开发者"]])
232230

233231

234232

@@ -250,8 +248,8 @@ async def parseDanMu(self, messages):
250248
self.api.post_watching_history(self.bilibili.csrf,real_roomid)
251249
result = self.api.check_room_true(real_roomid)
252250
if True in result:
253-
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "WARNING:检测到房间",
254-
str(real_roomid).center(9), "的钓鱼操作")
251+
self.printer.printlist_append(['join_lottery','','debug', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "WARNING:检测到房间",
252+
str(real_roomid).center(9), "的钓鱼操作"])
255253
else:
256254
check_url = 'https://api.live.bilibili.com/AppSmallTV/index?' + temp_params + '&sign=' + str(hash.hexdigest())
257255
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(real_roomid).center(9), "的小电视抽奖")
@@ -272,7 +270,7 @@ async def parseDanMu(self, messages):
272270
resttime = response.json()['data']['unjoin'][j]['dtime']
273271
raffleid = response.json()['data']['unjoin'][j]['id']
274272
if raffleid not in self.bilibili.TV_raffleid_list:
275-
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(real_roomid).center(9), "的小电视抽奖")
273+
self.printer.printlist_append(['join_lottery','小电视','user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(real_roomid).center(9), "的小电视抽奖"])
276274
self.bilibili.TV_raffleid_list.append(raffleid)
277275
self.bilibili.TV_roomid_list.append(real_roomid)
278276
self.bilibili.TV_time_list.append(resttime)
@@ -298,11 +296,12 @@ async def parseDanMu(self, messages):
298296
# real_roomid) + '&raffleId=' + str(raffleid)
299297
# #response1 = requests.get(url1, headers=headers)
300298
response2 = requests.get(true_url,headers=self.bilibili.appheaders)
301-
print("# 小电视道具抽奖状态:",response2.json()['msg'])
299+
self.printer.printlist_append(['join_lottery','小电视','user', "# 小电视道具抽奖状态:",response2.json()['msg']])
302300
break
303301

304302
except:
305303
pass
304+
self.printer.printlist_append(['join_lottery','小电视','user', "# error", response.json()])
306305
if cmd == 'GUARD_MSG':
307306
try:
308307
print(dic)
@@ -338,5 +337,5 @@ async def parseDanMu(self, messages):
338337
print("# 获取到某个总督的奖励:",response2.json()['data']['message'])
339338

340339
except:
341-
print("# 没领取到奖励,请联系开发者")
340+
self.printer.printlist_append(['join_lotter','','develop', "# 没领取到奖励,请联系开发者"])
342341
return

conf/user.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ platform = other
77
username =
88
password =
99

10+
[print_control]
11+
join_lottery = user
12+
return_lotteryresult = user
13+
danmu = user
14+
普通送礼提示 = True
15+
弹幕 = False
16+
17+
18+
19+

configloader.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, colorfile, userfile, bilibilifile):
2323
# print(self.dic_color)
2424

2525
self.dic_user = self.load_user(userfile)
26-
# print(self.dic_user)
26+
#print(self.dic_user)
2727

2828
self.dic_bilibili = self.load_bilibili(bilibilifile)
2929
# print(self.dic_bilibili)
@@ -89,7 +89,21 @@ def load_user(self, file):
8989
# cf_user.read(file)
9090
cf_user.read_file(codecs.open(file, "r", "utf8"))
9191
# print(cf_user._sections['platform']['platform'])
92-
return cf_user._sections
92+
dic_user = cf_user._sections
93+
dictionary ={
94+
'True':True,
95+
'False': False,
96+
'user': 0,
97+
'debug': 1
98+
}
99+
100+
for i in dic_user['print_control'].keys():
101+
dic_user['print_control'][i] = dictionary[dic_user['print_control'][i]]
102+
103+
return dic_user
104+
105+
106+
93107

94108

95109
# configloader = ConfigLoader("color.conf", "user.conf", "bilibili.conf")

printer.py

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
except ImportError:
44
pass
55
import webcolors
6-
6+
import asyncio
77

88
# "#969696"
99
def hex_to_rgb_percent(hex_str):
1010
color = webcolors.hex_to_rgb_percent(hex_str)
1111
# print([float(i.strip('%'))/100.0 for i in color])
1212
return [float(i.strip('%'))/100.0 for i in color]
1313

14+
15+
16+
def level(str):
17+
if str == "user":
18+
return 0
19+
if str == "debug":
20+
return 1
21+
1422
class Printer():
1523
def __init__(self, configloader):
1624
self.configloader = configloader
25+
self.printlist=[]
1726
def concole_print(self, msg, color=[]):
1827
if color:
1928
for i, j in zip(msg, color):
@@ -22,8 +31,56 @@ def concole_print(self, msg, color=[]):
2231
print()
2332
console.set_color()
2433
else:
25-
print(''.join(msg))
26-
34+
print(''.join(msg))
35+
36+
def printlist_append(self, dic):
37+
tag = False
38+
dic_printcontrol = self.configloader.dic_user['print_control']
39+
if dic[0] in dic_printcontrol.keys():
40+
if dic_printcontrol[dic[0]] >= level(dic[2]):
41+
tag = True
42+
if dic[1] in dic_printcontrol.keys():
43+
tag = dic_printcontrol[dic[1]]
44+
if tag:
45+
if dic[1] == '弹幕':
46+
list_msg, list_color = self.print_danmu_msg(dic[3])
47+
self.printlist.append([0, list_msg, list_color])
48+
return
49+
50+
if isinstance(dic[3], list):
51+
# print(dic[3])
52+
# [[list]]
53+
self.printlist.append([dic[3]])
54+
else:
55+
# print(dic[3:])
56+
# [ss, ss]
57+
self.printlist.append(dic[3:])
58+
59+
async def clean_printlist(self):
60+
61+
while True:
62+
# if self.printlist:
63+
# print(self.printlist)
64+
for i in self.printlist:
65+
if i[0] == 0:
66+
if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
67+
self.concole_print(i[1], i[2])
68+
else:
69+
self.concole_print(i[1])
70+
71+
72+
elif isinstance(i[0], list):
73+
#print("qqqqqq")
74+
# print(i)
75+
for j in i[0]:
76+
print(j)
77+
else:
78+
print(' '.join(i))
79+
self.printlist=[]
80+
await asyncio.sleep(0.5)
81+
82+
83+
2784

2885
def print_danmu_msg(self, dic):
2986
info = dic['info']
@@ -72,10 +129,12 @@ def print_danmu_msg(self, dic):
72129

73130
list_msg.append(':' + info[1])
74131
list_color.append([])
75-
if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
76-
self.concole_print(list_msg, list_color)
77-
else:
78-
self.concole_print(list_msg)
132+
return list_msg, list_color
133+
134+
# if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
135+
# self.concole_print(list_msg, list_color)
136+
# else:
137+
# self.concole_print(list_msg)
79138

80139

81140

run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
task1.run(),
3232
task2.run(),
3333
task4.connect(),
34-
task3.query()
34+
task3.query(),
35+
printer.clean_printlist()
3536
]
3637

3738
loop = asyncio.get_event_loop()

0 commit comments

Comments
 (0)