Temp commit
This commit is contained in:
parent
4866901c4b
commit
57f71eb0b9
10 changed files with 111 additions and 14 deletions
32
src/__main__.py
Normal file
32
src/__main__.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""
|
||||
Author: Jose Stovall
|
||||
Description: A Flask API service for the running Minecraft server statuses
|
||||
"""
|
||||
|
||||
from flask import jsonify, request, Flask
|
||||
from flask_cors import CORS
|
||||
from common import get_server_info
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
try:
|
||||
data = get_server_info(all=request.args.get("all"))
|
||||
|
||||
if request.args.get("sort"):
|
||||
data = sorted(data, key=lambda x: x[request.args.get("sort")])
|
||||
|
||||
resp = jsonify(data)
|
||||
resp.status_code = 200
|
||||
return resp
|
||||
except KeyError as e:
|
||||
resp = jsonify({"error": f"Failed to find key {str(e)}"})
|
||||
resp.status_code = 422
|
||||
return resp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
Loading…
Reference in a new issue