You've already forked XiguaLiveDanmakuHelper
抽奖信息可从弹幕中提取,可实时检测抽奖避免刷屏
This commit is contained in:
17
Lottery.py
17
Lottery.py
@ -18,7 +18,7 @@ class Lottery:
|
|||||||
self.parse(json)
|
self.parse(json)
|
||||||
|
|
||||||
def parse(self, json):
|
def parse(self, json):
|
||||||
if "lottery_info" not in json or json["lottery_info"] is not None:
|
if "lottery_info" in json and json["lottery_info"] is not None:
|
||||||
self.isActive = int(json["lottery_info"]["status"]) > 0
|
self.isActive = int(json["lottery_info"]["status"]) > 0
|
||||||
self.ID = json["lottery_info"]["lottery_id"]
|
self.ID = json["lottery_info"]["lottery_id"]
|
||||||
for i in json["lottery_info"]['conditions']:
|
for i in json["lottery_info"]['conditions']:
|
||||||
@ -29,13 +29,16 @@ class Lottery:
|
|||||||
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"])
|
_delta = int(json["lottery_info"]["draw_time"]) - int(json["lottery_info"]["current_time"])
|
||||||
self.finish = time.time()+_delta+1
|
self.finish = time.time()+_delta+1
|
||||||
|
elif "extra" in json and json["extra"] is not None:
|
||||||
|
if "lottery_info" in json["extra"] and json["extra"]["lottery_info"] is not None:
|
||||||
|
return self.parse(json["extra"])
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.finish > time.time():
|
if self.isActive:
|
||||||
self.checkFinished()
|
if not self.isFinished and self.finish > time.time():
|
||||||
return True
|
self.checkFinished()
|
||||||
else:
|
return True
|
||||||
return False
|
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={}"
|
||||||
@ -47,7 +50,7 @@ class Lottery:
|
|||||||
self.isActive = False
|
self.isActive = False
|
||||||
self.isFinished = False
|
self.isFinished = False
|
||||||
return
|
return
|
||||||
self.isActive = int(d["lottery_info"]["status"]) == 1
|
self.isActive = int(d["lottery_info"]["status"]) > 0
|
||||||
self.isFinished = int(d["lottery_info"]["status"]) == 2
|
self.isFinished = int(d["lottery_info"]["status"]) == 2
|
||||||
self.joinedUserCount = int(d["lottery_info"]["candidate_num"])
|
self.joinedUserCount = int(d["lottery_info"]["candidate_num"])
|
||||||
if self.isFinished:
|
if self.isFinished:
|
||||||
|
12
api.py
12
api.py
@ -189,20 +189,22 @@ class XiGuaLiveApi:
|
|||||||
self.onLike(User(i))
|
self.onLike(User(i))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
self.lottery = Lottery(i)
|
||||||
self._updRoomCount += 1
|
self._updRoomCount += 1
|
||||||
if self.lottery is not None:
|
if self.lottery is not None or self.lottery.ID != 0:
|
||||||
self.lottery.update()
|
self.lottery.update()
|
||||||
|
if self.lottery.isFinished:
|
||||||
|
self.onLottery(self.lottery)
|
||||||
|
self.lottery = None
|
||||||
if self._updRoomCount > 120 or len(d['data']) == 0:
|
if self._updRoomCount > 120 or len(d['data']) == 0:
|
||||||
if self.lottery.isFinished:
|
|
||||||
self.onLottery(self.lottery)
|
|
||||||
self.lottery = None
|
|
||||||
self.updRoomInfo()
|
self.updRoomInfo()
|
||||||
self._updRoomCount = 0
|
self._updRoomCount = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
name = "永恒de草薙"
|
# name = "永恒de草薙"
|
||||||
|
name = "尤美"
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
if sys.argv[-1] == "d":
|
if sys.argv[-1] == "d":
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
Reference in New Issue
Block a user