diff --git a/app.py b/app.py index 2b3da3e..9072f31 100644 --- a/app.py +++ b/app.py @@ -4,18 +4,24 @@ import chevron import requests import json from pprint import pprint +from flask import Flask, request stream_data = json.load(open('resources/data.json', 'r')) +session = requests.Session() +session.auth = ('admin', stream_data['stream_key']) + +app = Flask(__name__) def render(data={}): return chevron.render(template=open('index.html', 'r'), data=data) -def getStatus(): - response = requests.get(stream_data['stream_url'] + '/api/yp') +@app.route("/api/serverstatus", methods=['GET']) +def getServerStatus(): + response = session.get(stream_data['stream_url'] + '/api/yp') response_data = response.json() - return { + return json.dumps({ 'name': response_data['name'], 'online': response_data['online'], 'overallMaxViewerCount': response_data['overallMaxViewerCount'], @@ -23,11 +29,46 @@ def getStatus(): 'streamTitle': response_data['streamTitle'], 'viewerCount': response_data['viewerCount'], 'description': response_data['description'], - } + 'tags': response_data['tags'], + 'nsfw': response_data['nsfw'], + }) +@app.route("/api/update/streamtitle", methods=['POST']) def updateStreamTitle(): - pass + response = session.post( + stream_data['stream_url'] + '/api/admin/config/streamtitle', + data=json.dumps({'value': request.json()}) + ) + print(response.json()) + return response.status_code -print(render(getStatus())) +@app.route('/api/update/servertags', methods=['POST']) +def updateServerTags(tags_list: list): + response = session.post( + stream_data['stream_url'] + '/api/admin/config/tags', + data=json.dumps({ + 'value': tags_list + }) + ) + return response.status_code, json.loads(response.text) + + +@app.route('/api/update/nsfw', methods=['POST']) +def updateServerNSFW(boolean: bool): + response = session.post( + stream_data['stream_url'] + '/api/admin/config/nsfw', + data=json.dumps({ + 'value': boolean + }) + ) + return response.status_code, json.loads(response.text) + + +@app.route("/") +def index(): + return render(json.loads(getServerStatus())) + + +print(getServerStatus()[1]) diff --git a/index.html b/index.html index 2d63f85..4df98ed 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - {{name}} + {{name}} @@ -15,12 +15,14 @@
-

{{streamTitle}}

-

Stream online? {{online}}

+

{{streamTitle}}

+

Stream online? {{online}}


-

Current Viewers: {{viewerCount}}

-

Session Max Viewers: {{sessionMaxViewerCount}}

-

Overall Max Viewers: {{overallMaxViewerCount}}

+

Current Viewers: {{viewerCount}}

+

Session Max Viewers: {{sessionMaxViewerCount}}

+

Overall Max Viewers: {{overallMaxViewerCount}}

+
+

Current tags: