改善代码兼容性

This commit is contained in:
Jerry Yan 2019-04-07 16:01:27 +08:00 committed by JerryYan
parent 00190468a8
commit 5fa4ee929e
8 changed files with 56 additions and 39 deletions

View File

@ -114,7 +114,7 @@ def appendError(obj):
class downloader(XiGuaLiveApi): class downloader(XiGuaLiveApi):
files = [] files = []
playlist: str = None playlist = None
def updRoomInfo(self): def updRoomInfo(self):
global broadcaster, isBroadcasting, updateTime global broadcaster, isBroadcasting, updateTime

View File

@ -4,9 +4,9 @@ from .Lottery import Lottery
class Chat: class Chat:
content: str ="" content =""
user: User=None user=None
filterString:list = ["",] filterString = ["",]
isFiltered = False isFiltered = False
def __init__(self, json=None, lottery:Lottery = None): def __init__(self, json=None, lottery:Lottery = None):

View File

@ -3,12 +3,12 @@ from .User import User
class Gift: class Gift:
ID:int = 0 ID = 0
count:int = 0 count = 0
roomID:int = 0 roomID = 0
giftList:dict = {} giftList = {}
amount:int = 0 amount = 0
user:User = None user = None
def __init__(self, json=None): def __init__(self, json=None):
if json: if json:

View File

@ -5,14 +5,14 @@ from .LuckyUser import LuckyUser
class Lottery: class Lottery:
ID: int = 0 ID = 0
isActive = False isActive = False
content = "" content = ""
isFinished = False isFinished = False
luckyUsers = [] luckyUsers = []
joinedUserCount = 0 joinedUserCount = 0
prizeName = "" prizeName = ""
finish:int = 0 finish = 0
def __init__(self, json=None): def __init__(self, json=None):
if json: if json:

View File

@ -2,9 +2,9 @@ from .User import User
class MemberMsg: class MemberMsg:
type:int = 0 type = 0
content:str = "" content = ""
user:User = None user = None
def __init__(self, json=None): def __init__(self, json=None):
if json: if json:

View File

@ -1,11 +1,11 @@
class User: class User:
ID: int = 0 ID = 0
name: str = "" name = ""
brand: str = "" brand = ""
level: int = 0 level = 0
type: int = 0 type = 0
block: bool = False block = False
mute: bool = False mute = False
def __init__(self, json=None): def __init__(self, json=None):
if json: if json:
@ -47,8 +47,7 @@ class User:
else: else:
if self.type != 0: if self.type != 0:
return "[{}{}]{}".format(self.brand, self.level, self.name) return "[{}{}]{}".format(self.brand, self.level, self.name)
return "<{}{}>{}".format(self.brand,self.level,self.name) return "<{}{}>{}".format(self.brand, self.level, self.name)
def __unicode__(self): def __unicode__(self):
return self.__str__() return self.__str__()

View File

@ -1,3 +1,5 @@
from time import sleep
from flask import Flask, jsonify, request from flask import Flask, jsonify, request
import Common import Common
import threading import threading
@ -39,6 +41,18 @@ def getAllStats():
}}) }})
@app.route("/stats/broadcast", methods=["GET"])
def geBroadcastStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"broadcast": {
"broadcaster": Common.broadcaster.__str__(),
"isBroadcasting": Common.isBroadcasting,
"streamUrl": Common.streamUrl,
"updateTime": Common.updateTime
}
}})
@app.route("/stats/download", methods=["GET"]) @app.route("/stats/download", methods=["GET"])
def geDownloadStats(): def geDownloadStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{ return jsonify({"message":"ok","code":200,"status":0,"data":{
@ -62,7 +76,11 @@ def getUploadStats():
t = threading.Thread(target=RUN, args=(Common.config['l_u'],)) t = threading.Thread(target=RUN, args=(Common.config['l_u'],))
t.setDaemon(True) t.setDaemon(True)
t.start()
if __name__ == "__main__": while True:
t.start() if t.is_alive():
app.run() sleep(240)
else:
t = threading.Thread(target=RUN, args=(Common.config['l_u'],))
t.setDaemon(True)
t.start()

22
api.py
View File

@ -12,21 +12,21 @@ import time
s = requests.Session() s = requests.Session()
DEBUG: bool = False DEBUG = False
class XiGuaLiveApi: class XiGuaLiveApi:
isLive: bool = False isLive = False
isValidRoom: bool = False isValidRoom = False
_rawRoomInfo = {} _rawRoomInfo = {}
name: str = "" name = ""
roomID: int = 0 roomID = 0
roomTitle: str = "" roomTitle = ""
roomLiver: User = None roomLiver = None
roomPopularity: int = 0 roomPopularity = 0
_cursor:str = "0" _cursor = "0"
_updRoomCount:int = 0 _updRoomCount = 0
lottery:Lottery = None lottery = None
def __init__(self, name: str = "永恒de草薙"): def __init__(self, name: str = "永恒de草薙"):
self.name = name self.name = name