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

Commit

Permalink
Optimize draw lottery
Browse files Browse the repository at this point in the history
因为最近出现了连续两个空id导致提前结束实物抽奖的获取,故优化一下这里的跳出逻辑。
B站删除哔考分区导致持续获取被风控,故增加分区房间获取不到时的简易处理。
  • Loading branch information
yawwwwwn committed Sep 4, 2019
1 parent 4ec4161 commit 23ae605
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 6 additions & 1 deletion MultiRoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ async def area2room(area_id):
response = await bilibili().bili_section_get(url)
json_response = await response.json(content_type=None)
checklen = len(json_response['data'])
if not checklen:
Printer().printer(f"{area_id}号分区当前无开播房间,5分钟后重新获取", "Error", "red")
await asyncio.sleep(300)
continue
rand_num = random.randint(0, checklen-1)
new_area_id = json_response['data'][rand_num]['parent_id']
if not new_area_id == int(area_id):
Expand All @@ -28,7 +32,8 @@ async def area2room(area_id):
new_area = str(new_area_id) + json_response['data'][rand_num]['parent_name']
return [area_room, new_area]
else:
Printer().printer("检测到获取房间未开播,立即尝试重新获取", "Error", "red")
Printer().printer("检测到获取房间未开播,1秒后尝试重新获取", "Error", "red")
await asyncio.sleep(1)
except Exception as e:
Printer().printer(f"获取房间列表失败,5s后进行下次尝试 {repr(e)}", "Error", "red")
await asyncio.sleep(5)
Expand Down
14 changes: 8 additions & 6 deletions OnlineHeart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
import datetime
import asyncio
import queue
from printer import Printer


Expand Down Expand Up @@ -68,17 +69,19 @@ async def guard_lottery(self):
Printer().printer(
f"房间 {OriginRoomId} 编号 {GuardId} 的上船亲密度领取出错: {json_response2}",
"Error", "red")

await asyncio.sleep(0.2)

async def draw_lottery(self):
black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", # 已经出现
"測一測", "TEST", "Test", "t-e-s-t"] # 合理猜想
last_lottery = 0
former_lottery = queue.Queue(maxsize=4)
[former_lottery.put(True) for _ in range(4)]
for i in range(390, 600):
response = await bilibili().get_lotterylist(i)
json_response = await response.json()
former_lottery.get()
former_lottery.put(not json_response['code'])
if json_response['code'] == 0:
last_lottery = 0
title = json_response['data']['title']
check = len(json_response['data']['typeB'])
for g in range(check):
Expand All @@ -98,10 +101,9 @@ async def draw_lottery(self):
json_response1 = await response1.json(content_type=None)
Printer().printer(f"参与『{title}>>>{jp_list}』抽奖回显: {json_response1}", "Lottery", "cyan")
else:
if not last_lottery == 0: # 因为有中途暂时空一个-400的情况
if not any(former_lottery.queue): # 检查最近4个活动id是否都-400
break
else:
last_lottery = json_response['code']
await asyncio.sleep(0.2)

async def run(self):
while 1:
Expand Down

0 comments on commit 23ae605

Please sign in to comment.