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

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
修复可能的卡死原因——连接舰长与PK服务器未设置timeout(我记错了以为requests有default的timeout来着= =)
应要求修改初始休眠状态,使休眠执行更严格
修复获取勋章时主站勋章没有直播间号的问题
修复送礼时海外无法获取直播间信息报错的问题
  • Loading branch information
yawwwwwn committed Mar 3, 2020
1 parent 66db5ca commit 7314876
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ async def guard_list(self):
headers = {
"User-Agent": "bilibili-live-tools/" + str(self.dic_bilibili['uid'])
}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=10)
return response

async def pk_list(self):
url = "http://118.25.108.153:8080/pk"
headers = {
"User-Agent": "bilibili-live-tools/" + str(self.dic_bilibili['uid'])
}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=10)
return response

async def get_lotterylist(self, i):
Expand Down
7 changes: 6 additions & 1 deletion biliconsole.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import utils
from statistics import Statistics
from printer import Printer
import traceback
import threading
import asyncio

Expand Down Expand Up @@ -75,7 +77,10 @@ async def run(self):
task = asyncio.ensure_future(i())
tasklist.append(task)
if tasklist:
await asyncio.wait(tasklist, return_when=asyncio.ALL_COMPLETED)
try:
await asyncio.wait(tasklist, return_when=asyncio.ALL_COMPLETED)
except Exception:
Printer().printer(traceback.format_exc(), "Error", "red")
# print('本批次结束')
else:
# print('本批次轮空')
Expand Down
7 changes: 6 additions & 1 deletion schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ class Schedule:
def __new__(cls, *args, **kw):
if not cls.instance:
cls.instance = super(Schedule, cls).__new__(cls)
cls.instance.scheduled_sleep = False
cls.instance.scheduled_sleep = True
return cls.instance

async def run(self, schedule_str):
if schedule_str == '':
Printer().printer("请填入定时休眠时间段", "Warning", "red")
self.scheduled_sleep = False
return
second_array = sorted([[sec_calc(*time_str.split(':')) for time_str in
time_str_pair.split('-')] for time_str_pair in schedule_str.split(';')])
second_array = [[start, end] for (start, end) in second_array if start != end]
if not len(second_array):
Printer().printer("请填入有效时间段", "Warning", "red")
self.scheduled_sleep = False
return
second_rearrng = [second_array[0]]
pos = 1
Expand All @@ -57,6 +59,9 @@ async def run(self, schedule_str):
if stage % 2 == 1:
self.scheduled_sleep = True
Printer().printer(f"当前处于定时休眠时间段内,下一次取消休眠时间为 {time_str_calc(sec_sequence[stage])}", "Info", "green")
else:
self.scheduled_sleep = False
Printer().printer(f"当前处于定时休眠时间段外,下一次开始休眠时间为 {time_str_calc(sec_sequence[stage])}", "Info", "green")
while True:
sleep_time = (sec_sequence[stage] - sec_now()) % 86400
# 避免因误差刚好过了下个时间点
Expand Down
5 changes: 4 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def fetch_medal(printer=True):
if json_response['code'] == 0:
for i in json_response['data']['fansMedalList']:
if i['status'] == 1:
roomid = i['roomid']
roomid = i.get('roomid', 0) # 主站获取的勋章没有直播间
today_feed = i['today_feed']
day_limit = i['day_limit']
if printer:
Expand Down Expand Up @@ -205,6 +205,9 @@ async def check_taskinfo():
async def send_gift_web(roomid, giftid, giftnum, bagid):
response = await bilibili().request_check_room(roomid)
json_response = await response.json()
if json_response["code"] != 0:
Printer().printer(f"获取送礼房间{roomid}信息出错: {json_response}", "Error", "red")
return
ruid = json_response['data']['uid']
biz_id = json_response['data']['room_id']
response1 = await bilibili().request_send_gift_web(giftid, giftnum, bagid, ruid, biz_id)
Expand Down

0 comments on commit 7314876

Please sign in to comment.