diff --git a/bilibili.py b/bilibili.py index 188f2d3..8427f20 100644 --- a/bilibili.py +++ b/bilibili.py @@ -417,7 +417,7 @@ 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): @@ -425,7 +425,7 @@ async def pk_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 get_lotterylist(self, i): diff --git a/biliconsole.py b/biliconsole.py index 1ddf2b4..05988bf 100644 --- a/biliconsole.py +++ b/biliconsole.py @@ -1,5 +1,7 @@ import utils from statistics import Statistics +from printer import Printer +import traceback import threading import asyncio @@ -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('本批次轮空') diff --git a/schedule.py b/schedule.py index 34ae56e..b44b616 100644 --- a/schedule.py +++ b/schedule.py @@ -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 @@ -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 # 避免因误差刚好过了下个时间点 diff --git a/utils.py b/utils.py index 518fb30..eaaddea 100644 --- a/utils.py +++ b/utils.py @@ -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: @@ -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)