Updates get_status endpoint for compatibility
- get_status endpoint now actually accesses two different endpoints from the owncast server api, as some of the endpoints have changed since development began - adds various documentation to app.py
This commit is contained in:
parent
dbbf1b757c
commit
2306bbc2e7
30
app.py
30
app.py
|
@ -55,28 +55,48 @@ app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def render(data={}):
|
def render(data={}):
|
||||||
|
""" Template rendering function using mustache (via the pypi chevron
|
||||||
|
implementation.
|
||||||
|
|
||||||
|
:returns: A full HTML template with relevant data from the server.
|
||||||
|
"""
|
||||||
return chevron.render(template=open('index.mustache', 'r'), data=data)
|
return chevron.render(template=open('index.mustache', 'r'), data=data)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/serverstatus", methods=['GET'])
|
@app.route("/api/serverstatus", methods=['GET'])
|
||||||
def getServerStatus():
|
def getServerStatus():
|
||||||
|
""" Obtains useful information from the server from either /api/yp or
|
||||||
|
/api/status.
|
||||||
|
|
||||||
|
:returns: the collected data as a JSON formatted dict.
|
||||||
|
"""
|
||||||
response = session.get(stream_data['stream_url'] + '/api/yp')
|
response = session.get(stream_data['stream_url'] + '/api/yp')
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
return json.dumps({
|
data = {
|
||||||
'name': response_data['name'],
|
'name': response_data['name'],
|
||||||
'online': response_data['online'],
|
'online': response_data['online'],
|
||||||
'overallMaxViewerCount': response_data['overallMaxViewerCount'],
|
'overallMaxViewerCount': response_data['overallMaxViewerCount'],
|
||||||
'sessionMaxViewerCount': response_data['sessionMaxViewerCount'],
|
'sessionMaxViewerCount': response_data['sessionMaxViewerCount'],
|
||||||
'streamTitle': response_data['streamTitle'],
|
|
||||||
'viewerCount': response_data['viewerCount'],
|
'viewerCount': response_data['viewerCount'],
|
||||||
'description': response_data['description'],
|
'description': response_data['description'],
|
||||||
'tags': response_data['tags'],
|
'tags': response_data['tags'],
|
||||||
'nsfw': response_data['nsfw'],
|
'nsfw': response_data['nsfw'],
|
||||||
})
|
}
|
||||||
|
|
||||||
|
response = session.get(stream_data['stream_url'] + '/api/status')
|
||||||
|
response_data = response.json()
|
||||||
|
|
||||||
|
data['streamTitle'] = response_data['streamTitle']
|
||||||
|
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/update/streamtitle", methods=['POST'])
|
@app.route("/api/update/streamtitle", methods=['POST'])
|
||||||
def updateStreamTitle():
|
def updateStreamTitle():
|
||||||
|
""" An endpoint to allow the user to update the stream title.
|
||||||
|
|
||||||
|
:returns: the status code of the post request made to the server.
|
||||||
|
"""
|
||||||
response = session.post(
|
response = session.post(
|
||||||
stream_data['stream_url'] + '/api/admin/config/streamtitle',
|
stream_data['stream_url'] + '/api/admin/config/streamtitle',
|
||||||
data=json.dumps({'value': request.get_json(force=True)})
|
data=json.dumps({'value': request.get_json(force=True)})
|
||||||
|
@ -108,6 +128,10 @@ def updateServerNSFW(boolean: bool):
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
""" A simple initial endpoint that loads in relevant data from the server.
|
||||||
|
|
||||||
|
:returns: the rendered template (see app.render for more)
|
||||||
|
"""
|
||||||
return render(json.loads(getServerStatus()))
|
return render(json.loads(getServerStatus()))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue