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:
Ariana Giroux 2022-08-04 17:33:59 -06:00
parent dbbf1b757c
commit 2306bbc2e7
1 changed files with 27 additions and 3 deletions

30
app.py
View File

@ -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()))