From 2306bbc2e77ad794e44710b688a6e8461ede0231 Mon Sep 17 00:00:00 2001 From: arianagiroux Date: Thu, 4 Aug 2022 17:33:59 -0600 Subject: [PATCH] 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 --- app.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 80e7555..4d3de8c 100755 --- a/app.py +++ b/app.py @@ -55,28 +55,48 @@ app = Flask(__name__) 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) @app.route("/api/serverstatus", methods=['GET']) 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_data = response.json() - return json.dumps({ + data = { 'name': response_data['name'], 'online': response_data['online'], 'overallMaxViewerCount': response_data['overallMaxViewerCount'], 'sessionMaxViewerCount': response_data['sessionMaxViewerCount'], - 'streamTitle': response_data['streamTitle'], 'viewerCount': response_data['viewerCount'], 'description': response_data['description'], 'tags': response_data['tags'], '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']) 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( stream_data['stream_url'] + '/api/admin/config/streamtitle', data=json.dumps({'value': request.get_json(force=True)}) @@ -108,6 +128,10 @@ def updateServerNSFW(boolean: bool): @app.route("/") 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()))