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

Commit

Permalink
Draw lottery result
Browse files Browse the repository at this point in the history
添加实物抽奖后的中奖查询
及时释放queue资源
NOTICE_MSG部分整理
  • Loading branch information
yawwwwwn committed Sep 19, 2019
1 parent 643a667 commit 8991654
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
16 changes: 15 additions & 1 deletion OnlineHeart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
import asyncio
import queue
from statistics import Statistics
from printer import Printer


Expand Down Expand Up @@ -71,8 +72,18 @@ async def guard_lottery(self):
"Error", "red")
await asyncio.sleep(0.2)

async def check_winner(self, i, g, start_time):
# 开奖5s后检查是否中奖
await asyncio.sleep(time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) - time.time() + 5)
response2 = await bilibili().get_winner_info(i, g)
json_response2 = await response2.json(content_type=None)
for winner in json_response2["data"]["winnerList"]:
if winner["uid"] == bilibili().dic_bilibili['uid']:
Printer().printer(f'实物抽奖中中奖: {winner["giftTitle"]}', "Lottery", "cyan")
Statistics().add_to_result(winner["giftTitle"], 1)

async def draw_lottery(self):
black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", # 已经出现
black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", "我是抽奖标题", # 已经出现
"測一測", "TEST", "Test", "t-e-s-t"] # 合理猜想
former_lottery = queue.Queue(maxsize=4)
[former_lottery.put(True) for _ in range(4)]
Expand Down Expand Up @@ -100,10 +111,13 @@ async def draw_lottery(self):
response1 = await bilibili().get_gift_of_lottery(i, g)
json_response1 = await response1.json(content_type=None)
Printer().printer(f"参与『{title}>>>{jp_list}』抽奖回显: {json_response1}", "Lottery", "cyan")
start_time = json_response['data']['typeB'][g]["startTime"]
asyncio.ensure_future(self.check_winner(i, g, start_time))
else:
if not any(former_lottery.queue): # 检查最近4个活动id是否都-400
break
await asyncio.sleep(0.2)
del former_lottery

async def run(self):
while 1:
Expand Down
6 changes: 6 additions & 0 deletions bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ async def get_gift_of_lottery(self, i, g):
response1 = await self.bili_section_get(url1, headers=self.dic_bilibili['pcheaders'])
return response1

async def get_winner_info(self, i, g):
url2 = 'https://api.live.bilibili.com/lottery/v1/box/getWinnerGroupInfo?aid=' + \
str(i) + '&number=' + str(g + 1)
response2 = await self.bili_section_get(url2, headers=self.dic_bilibili['pcheaders'])
return response2

async def get_time_about_silver(self):
time = CurrentTime()
temp_params = 'access_key=' + self.dic_bilibili['access_key'] + '&actionKey=' + self.dic_bilibili[
Expand Down
22 changes: 13 additions & 9 deletions bilibiliCilent.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,24 @@ async def parseDanMu(self, messages):
# Printer().printer(f"出现了远古的SYS_GIFT,请尽快联系开发者{dic}", "Warning", "red")
pass
elif cmd == 'NOTICE_MSG':
# msg_type: 2 抽奖 (TV, 大楼, etc)
# 3 总督
# 6 风暴?
# msg_type: 1 小时榜首绘马大奖等通报
# 2 抽奖 (TV, 大楼, etc.)
# 3 舰队
# 4 总督进入直播间
# 5 当前房间高能大奖
# 6 风暴
# 8 任意门
if dic.get('msg_type') in [2,3,6,8]:
try:
# 9 活动中主播达成星级通报
try:
if dic.get('msg_type') in [2, 8]:
real_roomid = dic.get('real_roomid')
Printer().printer(f"检测到房间 {real_roomid} 的广播抽奖 @[{self.area}分区]{self._roomId}", "Lottery", "cyan")
Rafflehandler().append2list_TV(real_roomid)
Statistics().append2pushed_TVlist(real_roomid, self.area[0])
except:
Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red")
else:
Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green")
else:
Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green")
except Exception:
Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red")
elif cmd == 'SYS_MSG':
if set(dic) in [set(self.dic_bulletin), {'cmd', 'msg', 'msg_text'}, {'cmd', 'msg', 'url'}]:
Printer().printer(f"{dic['msg']} @[{self.area}分区]{self._roomId}", "Info", "green")
Expand Down

0 comments on commit 8991654

Please sign in to comment.