修复:因isValidRoom判断错误导致的无法获取弹幕,修正抽奖结束时间判断
This commit is contained in:
parent
81f730ea68
commit
1b920fa55c
12
Lottery.py
12
Lottery.py
@ -1,5 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
from LuckyUser import LuckyUser
|
from LuckyUser import LuckyUser
|
||||||
|
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ class Lottery:
|
|||||||
luckyUsers = []
|
luckyUsers = []
|
||||||
joinedUserCount = 0
|
joinedUserCount = 0
|
||||||
prizeName = ""
|
prizeName = ""
|
||||||
|
finish:int = 0
|
||||||
|
|
||||||
def __init__(self, json=None):
|
def __init__(self, json=None):
|
||||||
if json:
|
if json:
|
||||||
@ -26,6 +27,15 @@ class Lottery:
|
|||||||
self.content = i["content"]
|
self.content = i["content"]
|
||||||
self.joinedUserCount = int(json["lottery_info"]["candidate_num"])
|
self.joinedUserCount = int(json["lottery_info"]["candidate_num"])
|
||||||
self.prizeName = json["lottery_info"]["prize_info"]["name"]
|
self.prizeName = json["lottery_info"]["prize_info"]["name"]
|
||||||
|
_delta = int(json["lottery_info"]["draw_time"]) - int(json["lottery_info"]["current_time"])
|
||||||
|
self.finish = time.time()+_delta+1
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if self.finish > time.time():
|
||||||
|
self.checkFinished()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def checkFinished(self):
|
def checkFinished(self):
|
||||||
p = requests.get("https://i.snssdk.com/videolive/lottery/check_user_right?lottery_id={}"
|
p = requests.get("https://i.snssdk.com/videolive/lottery/check_user_right?lottery_id={}"
|
||||||
|
8
api.py
8
api.py
@ -104,7 +104,8 @@ class XiGuaLiveApi:
|
|||||||
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
|
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
|
||||||
"&format=json&keyword={}".format(self.name))
|
"&format=json&keyword={}".format(self.name))
|
||||||
d = p.json()
|
d = p.json()
|
||||||
if "data" in d:
|
self.isValidRoom = d["base_resp"]["status_code"] == 0
|
||||||
|
if "data" in d and d["data"] is not None:
|
||||||
for i in d["data"]:
|
for i in d["data"]:
|
||||||
if i["block_type"] != 0:
|
if i["block_type"] != 0:
|
||||||
continue
|
continue
|
||||||
@ -145,6 +146,7 @@ class XiGuaLiveApi:
|
|||||||
|
|
||||||
def getDanmaku(self):
|
def getDanmaku(self):
|
||||||
if not self.isValidRoom:
|
if not self.isValidRoom:
|
||||||
|
self.updRoomInfo()
|
||||||
return
|
return
|
||||||
p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}"
|
p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}"
|
||||||
"&version_code=730&device_platform=android".format(
|
"&version_code=730&device_platform=android".format(
|
||||||
@ -188,9 +190,9 @@ class XiGuaLiveApi:
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
self._updRoomCount += 1
|
self._updRoomCount += 1
|
||||||
if self._updRoomCount > 120 or len(d['data']) == 0:
|
|
||||||
if self.lottery is not None:
|
if self.lottery is not None:
|
||||||
self.lottery.checkFinished()
|
self.lottery.update()
|
||||||
|
if self._updRoomCount > 120 or len(d['data']) == 0:
|
||||||
if self.lottery.isFinished:
|
if self.lottery.isFinished:
|
||||||
self.onLottery(self.lottery)
|
self.onLottery(self.lottery)
|
||||||
self.lottery = None
|
self.lottery = None
|
||||||
|
@ -422,8 +422,6 @@ class Bilibili:
|
|||||||
"videos": self.videos}
|
"videos": self.videos}
|
||||||
)
|
)
|
||||||
print(r.text)
|
print(r.text)
|
||||||
for _p in self.files:
|
|
||||||
os.remove(_p.path)
|
|
||||||
|
|
||||||
def addChannel(self, name, intro=''):
|
def addChannel(self, name, intro=''):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user