处理逻辑优化
This commit is contained in:
parent
0e00579e13
commit
be194f4b64
16
api.py
16
api.py
@ -65,6 +65,8 @@ class XiGuaLiveApi:
|
|||||||
self.broadcaster = User()
|
self.broadcaster = User()
|
||||||
self.isValidUser = True
|
self.isValidUser = True
|
||||||
self.broadcaster.ID = int(name)
|
self.broadcaster.ID = int(name)
|
||||||
|
else:
|
||||||
|
self.name = str(name)
|
||||||
self.isLive = False
|
self.isLive = False
|
||||||
self._rawRoomInfo = {}
|
self._rawRoomInfo = {}
|
||||||
self.roomID = 0
|
self.roomID = 0
|
||||||
@ -91,6 +93,8 @@ class XiGuaLiveApi:
|
|||||||
self.roomPopularity = _data["data"]["popularity"]
|
self.roomPopularity = _data["data"]["popularity"]
|
||||||
|
|
||||||
def getJson(self, url, **kwargs):
|
def getJson(self, url, **kwargs):
|
||||||
|
if "timeout" not in kwargs:
|
||||||
|
kwargs["timeout"] = 10
|
||||||
try:
|
try:
|
||||||
p = self.s.get(url, **kwargs)
|
p = self.s.get(url, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -112,6 +116,8 @@ class XiGuaLiveApi:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def postJson(self, url, data, **kwargs):
|
def postJson(self, url, data, **kwargs):
|
||||||
|
if "timeout" not in kwargs:
|
||||||
|
kwargs["timeout"] = 10
|
||||||
try:
|
try:
|
||||||
p = self.s.post(url, data=data, **kwargs)
|
p = self.s.post(url, data=data, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -299,12 +305,18 @@ class XiGuaLiveApi:
|
|||||||
if "user_info" not in d and d["user_info"] is None:
|
if "user_info" not in d and d["user_info"] is None:
|
||||||
self.apiChangedError("Api发生改变,请及时联系我", d)
|
self.apiChangedError("Api发生改变,请及时联系我", d)
|
||||||
return False
|
return False
|
||||||
|
self._updRoomAt = datetime.now()
|
||||||
self.broadcaster = User(d)
|
self.broadcaster = User(d)
|
||||||
if not self._checkUsernameIsMatched():
|
if not self._checkUsernameIsMatched():
|
||||||
self.isLive = False
|
self.isLive = False
|
||||||
return False
|
return False
|
||||||
self.isLive = d["user_info"]["is_living"]
|
self.isLive = d["user_info"]["is_living"]
|
||||||
self._updRoomAt = datetime.now()
|
if d["user_info"]['live_info'] is None:
|
||||||
|
if d["live_data"] is None:
|
||||||
|
self.isLive = False
|
||||||
|
else:
|
||||||
|
self._rawRoomInfo = d["live_data"]['live_info']
|
||||||
|
else:
|
||||||
self._rawRoomInfo = d["user_info"]['live_info']
|
self._rawRoomInfo = d["user_info"]['live_info']
|
||||||
if self.isLive:
|
if self.isLive:
|
||||||
self.roomID = d["user_info"]['live_info']['room_id']
|
self.roomID = d["user_info"]['live_info']['room_id']
|
||||||
@ -316,7 +328,7 @@ class XiGuaLiveApi:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _getRoomInfo(self, force=False):
|
def _getRoomInfo(self, force=False):
|
||||||
if self.roomID == 0:
|
if self.roomID == 0 or not self.roomID:
|
||||||
self.isLive = False
|
self.isLive = False
|
||||||
return False
|
return False
|
||||||
if not force and (self._updRoomAt + timedelta(minutes=10) > datetime.now()):
|
if not force and (self._updRoomAt + timedelta(minutes=10) > datetime.now()):
|
||||||
|
Reference in New Issue
Block a user