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

Commit

Permalink
printer重构,实现debug
Browse files Browse the repository at this point in the history
  • Loading branch information
nico committed Apr 1, 2018
1 parent 7a42954 commit 6faf4db
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 28 deletions.
35 changes: 17 additions & 18 deletions bilibiliCilent.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ async def parseDanMu(self, messages):

if cmd == 'DANMU_MSG':
# print(dic)
# self.printer.print_danmu_msg(dic)
self.printer.printlist_append(['danmu', '弹幕', 'user', dic])
pass
if cmd == 'SYS_GIFT':
if 'giftId' in dic.keys():

if str(dic['giftId']) in self.bilibili.giftids_raffle.keys():
print(self.bilibili.giftids_raffle[str(dic['giftId'])])
self.printer.printlist_append(['join_lottery', '活动名称', 'user', self.bilibili.giftids_raffle[str(dic['giftId'])]])
headers = {
'Accept': 'application/json, text/plain, */*',
'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',
Expand All @@ -175,10 +175,10 @@ async def parseDanMu(self, messages):
self.api.post_watching_history(self.bilibili.csrf,text1)
result = self.api.check_room_true(text1)
if True in result:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),"WARNING:检测到房间",str(text1).center(9),"的钓鱼操作")
self.printer.printlist_append(['join_lottery', '钓鱼提醒', 'user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),"WARNING:检测到房间",str(text1).center(9),"的钓鱼操作"])
else:
url = 'http://api.live.bilibili.com/activity/v1/Raffle/check?roomid=' + str(text1)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(text1).center(9), "的活动抽奖")
self.printer.printlist_append(['join_lottery','','user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(text1).center(9), "的活动抽奖"])
response = requests.get(url, headers=headers)
checklen = response.json()['data']
num = len(checklen)
Expand All @@ -188,7 +188,7 @@ async def parseDanMu(self, messages):
resttime = response.json()['data'][j]['time']
raffleid = response.json()['data'][j]['raffleId']
if raffleid not in self.bilibili.activity_raffleid_list:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(text1).center(9), "的活动抽奖")
self.printer.printlist_append(['join_lottery','','user', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "参与了房间", str(text1).center(9), "的活动抽奖"])
self.bilibili.activity_raffleid_list.append(raffleid)
self.bilibili.activity_roomid_list.append(text1)
self.bilibili.activity_time_list.append(resttime)
Expand All @@ -211,24 +211,22 @@ async def parseDanMu(self, messages):
response1 = requests.get(true_url,params=params, headers=headers)
pc_response = requests.get(pc_url, headers=headers)
try:
print("# 移动端活动抽奖结果:", response1.json()['data']['gift_desc'])
self.printer.printlist_append(['join_lottery','','user', "# 移动端活动抽奖结果:", response1.json()['data']['gift_desc']])
except:
pass
try:
print("# 网页端活动抽奖状态:", pc_response.json()['message'])
self.printer.printlist_append(['join_lottery','','user', "# 网页端活动抽奖状态:", pc_response.json()['message']])
except:
pass
break
elif dic['giftId'] == 39:
print("节奏风暴")
self.printer.printlist_append(['join_lottery','','user', "节奏风暴"])
self.get_prensent_of_storm(dic)
else:
print(dic)
print("请联系开发者")
self.printer.printlist_append(['join_lottery','','debug', [dic, "请联系开发者"]])
else:
#print("礼物提示")
# print(dic["msg_text"])
pass
self.printer.printlist_append(['join_lottery','普通送礼提示','user', ['普通送礼提示', dic['msg_text']]])
#self.printer.printlist_append(['join_lottery','','debug', [dic, "请联系开发者"]])



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

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

except:
print("# 没领取到奖励,请联系开发者")
self.printer.printlist_append(['join_lotter','','develop', "# 没领取到奖励,请联系开发者"])
return
10 changes: 10 additions & 0 deletions conf/user.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ platform = other
username =
password =

[print_control]
join_lottery = user
return_lotteryresult = user
danmu = user
普通送礼提示 = True
弹幕 = False




18 changes: 16 additions & 2 deletions configloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, colorfile, userfile, bilibilifile):
# print(self.dic_color)

self.dic_user = self.load_user(userfile)
# print(self.dic_user)
#print(self.dic_user)

self.dic_bilibili = self.load_bilibili(bilibilifile)
# print(self.dic_bilibili)
Expand Down Expand Up @@ -89,7 +89,21 @@ def load_user(self, file):
# cf_user.read(file)
cf_user.read_file(codecs.open(file, "r", "utf8"))
# print(cf_user._sections['platform']['platform'])
return cf_user._sections
dic_user = cf_user._sections
dictionary ={
'True':True,
'False': False,
'user': 0,
'debug': 1
}

for i in dic_user['print_control'].keys():
dic_user['print_control'][i] = dictionary[dic_user['print_control'][i]]

return dic_user





# configloader = ConfigLoader("color.conf", "user.conf", "bilibili.conf")
73 changes: 66 additions & 7 deletions printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
except ImportError:
pass
import webcolors

import asyncio

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



def level(str):
if str == "user":
return 0
if str == "debug":
return 1

class Printer():
def __init__(self, configloader):
self.configloader = configloader
self.printlist=[]
def concole_print(self, msg, color=[]):
if color:
for i, j in zip(msg, color):
Expand All @@ -22,8 +31,56 @@ def concole_print(self, msg, color=[]):
print()
console.set_color()
else:
print(''.join(msg))

print(''.join(msg))

def printlist_append(self, dic):
tag = False
dic_printcontrol = self.configloader.dic_user['print_control']
if dic[0] in dic_printcontrol.keys():
if dic_printcontrol[dic[0]] >= level(dic[2]):
tag = True
if dic[1] in dic_printcontrol.keys():
tag = dic_printcontrol[dic[1]]
if tag:
if dic[1] == '弹幕':
list_msg, list_color = self.print_danmu_msg(dic[3])
self.printlist.append([0, list_msg, list_color])
return

if isinstance(dic[3], list):
# print(dic[3])
# [[list]]
self.printlist.append([dic[3]])
else:
# print(dic[3:])
# [ss, ss]
self.printlist.append(dic[3:])

async def clean_printlist(self):

while True:
# if self.printlist:
# print(self.printlist)
for i in self.printlist:
if i[0] == 0:
if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
self.concole_print(i[1], i[2])
else:
self.concole_print(i[1])


elif isinstance(i[0], list):
#print("qqqqqq")
# print(i)
for j in i[0]:
print(j)
else:
print(' '.join(i))
self.printlist=[]
await asyncio.sleep(0.5)




def print_danmu_msg(self, dic):
info = dic['info']
Expand Down Expand Up @@ -72,10 +129,12 @@ def print_danmu_msg(self, dic):

list_msg.append(':' + info[1])
list_color.append([])
if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
self.concole_print(list_msg, list_color)
else:
self.concole_print(list_msg)
return list_msg, list_color

# if (self.configloader.dic_user['platform']['platform'] == 'ios_pythonista'):
# self.concole_print(list_msg, list_color)
# else:
# self.concole_print(list_msg)



Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
task1.run(),
task2.run(),
task4.connect(),
task3.query()
task3.query(),
printer.clean_printlist()
]

loop = asyncio.get_event_loop()
Expand Down

0 comments on commit 6faf4db

Please sign in to comment.