|
6 | 6 | import datetime |
7 | 7 | import asyncio |
8 | 8 | import queue |
| 9 | +from statistics import Statistics |
9 | 10 | from printer import Printer |
10 | 11 |
|
11 | 12 |
|
@@ -71,8 +72,18 @@ async def guard_lottery(self): |
71 | 72 | "Error", "red") |
72 | 73 | await asyncio.sleep(0.2) |
73 | 74 |
|
| 75 | + async def check_winner(self, i, g, start_time): |
| 76 | + # 开奖5s后检查是否中奖 |
| 77 | + await asyncio.sleep(time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) - time.time() + 5) |
| 78 | + response2 = await bilibili().get_winner_info(i, g) |
| 79 | + json_response2 = await response2.json(content_type=None) |
| 80 | + for winner in json_response2["data"]["winnerList"]: |
| 81 | + if winner["uid"] == bilibili().dic_bilibili['uid']: |
| 82 | + Printer().printer(f'实物抽奖中中奖: {winner["giftTitle"]}', "Lottery", "cyan") |
| 83 | + Statistics().add_to_result(winner["giftTitle"], 1) |
| 84 | + |
74 | 85 | async def draw_lottery(self): |
75 | | - black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", # 已经出现 |
| 86 | + black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", "我是抽奖标题", # 已经出现 |
76 | 87 | "測一測", "TEST", "Test", "t-e-s-t"] # 合理猜想 |
77 | 88 | former_lottery = queue.Queue(maxsize=4) |
78 | 89 | [former_lottery.put(True) for _ in range(4)] |
@@ -100,10 +111,13 @@ async def draw_lottery(self): |
100 | 111 | response1 = await bilibili().get_gift_of_lottery(i, g) |
101 | 112 | json_response1 = await response1.json(content_type=None) |
102 | 113 | Printer().printer(f"参与『{title}>>>{jp_list}』抽奖回显: {json_response1}", "Lottery", "cyan") |
| 114 | + start_time = json_response['data']['typeB'][g]["startTime"] |
| 115 | + asyncio.ensure_future(self.check_winner(i, g, start_time)) |
103 | 116 | else: |
104 | 117 | if not any(former_lottery.queue): # 检查最近4个活动id是否都-400 |
105 | 118 | break |
106 | 119 | await asyncio.sleep(0.2) |
| 120 | + del former_lottery |
107 | 121 |
|
108 | 122 | async def run(self): |
109 | 123 | while 1: |
|
0 commit comments