优化更新时间间隔
This commit is contained in:
parent
9b2f1a744f
commit
9fb552e6dc
22
api.py
22
api.py
@ -9,6 +9,7 @@ from Struct.Chat import Chat
|
|||||||
from Struct.Lottery import Lottery
|
from Struct.Lottery import Lottery
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
@ -24,7 +25,6 @@ class XiGuaLiveApi:
|
|||||||
roomLiver = None
|
roomLiver = None
|
||||||
roomPopularity = 0
|
roomPopularity = 0
|
||||||
_cursor = "0"
|
_cursor = "0"
|
||||||
_updRoomCount = 0
|
|
||||||
lottery = None
|
lottery = None
|
||||||
s = requests.session()
|
s = requests.session()
|
||||||
|
|
||||||
@ -35,7 +35,8 @@ class XiGuaLiveApi:
|
|||||||
:param name: 主播名
|
:param name: 主播名
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.updRoomInfo()
|
self._updRoomAt = datetime.now()
|
||||||
|
self.updRoomInfo(True)
|
||||||
|
|
||||||
def _updateRoomPopularity(self, _data):
|
def _updateRoomPopularity(self, _data):
|
||||||
"""
|
"""
|
||||||
@ -215,11 +216,14 @@ class XiGuaLiveApi:
|
|||||||
self.lottery = l
|
self.lottery = l
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def updRoomInfo(self):
|
def updRoomInfo(self, force=False):
|
||||||
"""
|
"""
|
||||||
更新房间信息
|
更新房间信息
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if not force and self._updRoomAt > (datetime.now() - timedelta(minutes=2)):
|
||||||
|
return self.isLive
|
||||||
|
self._updRoomAt = datetime.now()
|
||||||
if self.isLive:
|
if self.isLive:
|
||||||
return self._updateRoomOnly()
|
return self._updateRoomOnly()
|
||||||
else:
|
else:
|
||||||
@ -304,14 +308,13 @@ class XiGuaLiveApi:
|
|||||||
elif i["common"]['method'] == "VideoLiveControlMessage":
|
elif i["common"]['method'] == "VideoLiveControlMessage":
|
||||||
print("消息:", "主播离开一小会")
|
print("消息:", "主播离开一小会")
|
||||||
# 这个消息代表主播下播了,直接更新房间信息
|
# 这个消息代表主播下播了,直接更新房间信息
|
||||||
self.updRoomInfo()
|
self.updRoomInfo(True)
|
||||||
elif i["common"]['method'] == "VideoLiveDiggMessage":
|
elif i["common"]['method'] == "VideoLiveDiggMessage":
|
||||||
self.onLike(User(i))
|
self.onLike(User(i))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if self.lottery is None or self.lottery.ID == 0:
|
if self.lottery is None or self.lottery.ID == 0:
|
||||||
self.lottery = Lottery(i)
|
self.lottery = Lottery(i)
|
||||||
self._updRoomCount += 1
|
|
||||||
# 更新抽奖信息
|
# 更新抽奖信息
|
||||||
if self.lottery is not None and self.lottery.ID != 0:
|
if self.lottery is not None and self.lottery.ID != 0:
|
||||||
self.lottery.update()
|
self.lottery.update()
|
||||||
@ -319,10 +322,7 @@ class XiGuaLiveApi:
|
|||||||
self.onLottery(self.lottery)
|
self.onLottery(self.lottery)
|
||||||
self.lottery = None
|
self.lottery = None
|
||||||
# 2分钟自动更新下房间信息
|
# 2分钟自动更新下房间信息
|
||||||
if self._updRoomCount > 120 or len(d['data']) == 0:
|
self.updRoomInfo(len(d['data']) == 0)
|
||||||
self.updRoomInfo()
|
|
||||||
self._updRoomCount = 0
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -347,8 +347,6 @@ if __name__ == "__main__":
|
|||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
time.sleep(1)
|
|
||||||
else:
|
else:
|
||||||
print("主播未开播,等待1分钟后重试")
|
print("主播未开播,等待2分钟后重试")
|
||||||
time.sleep(60)
|
|
||||||
api.updRoomInfo()
|
api.updRoomInfo()
|
||||||
|
@ -113,7 +113,6 @@ def run():
|
|||||||
if not Common.api.isValidRoom:
|
if not Common.api.isValidRoom:
|
||||||
Common.appendError("[{}]房间未找到".format(Common.config["l_u"]))
|
Common.appendError("[{}]房间未找到".format(Common.config["l_u"]))
|
||||||
return
|
return
|
||||||
_count = 0
|
|
||||||
while True:
|
while True:
|
||||||
if Common.api.isLive and not Common.forceNotBroadcasting:
|
if Common.api.isLive and not Common.forceNotBroadcasting:
|
||||||
if not Common.forceNotDownload:
|
if not Common.forceNotDownload:
|
||||||
@ -122,15 +121,12 @@ def run():
|
|||||||
awakeUpload()
|
awakeUpload()
|
||||||
if not Common.forceNotEncode:
|
if not Common.forceNotEncode:
|
||||||
awakeEncode()
|
awakeEncode()
|
||||||
if _count % 15 == 14:
|
try:
|
||||||
try:
|
Common.api.updRoomInfo()
|
||||||
Common.api.updRoomInfo()
|
except Exception as e:
|
||||||
_count = 0
|
Common.appendError(e.__str__())
|
||||||
_count_error = 0
|
time.sleep(5)
|
||||||
except Exception as e:
|
continue
|
||||||
Common.appendError(e.__str__())
|
|
||||||
time.sleep(5)
|
|
||||||
continue
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@ -148,4 +144,4 @@ def run():
|
|||||||
Common.forceStartUploadThread = False
|
Common.forceStartUploadThread = False
|
||||||
if Common.doDelay():
|
if Common.doDelay():
|
||||||
Common.uploadQueue.put(True)
|
Common.uploadQueue.put(True)
|
||||||
time.sleep(60)
|
time.sleep(15)
|
||||||
|
Reference in New Issue
Block a user