-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
29 lines (23 loc) · 944 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from flask import Flask
import subprocess
import shlex
app = Flask(__name__)
def build_error_response(message):
return "{ \"error\": \"" + message + "\" }"
def run_command(command):
try:
result = subprocess.run(shlex.split(command), check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)
return result.stdout
except subprocess.CalledProcessError as e:
return build_error_response(e.stderr)
@app.route("/<game_name>/<variant_id>/")
def getstart(game_name, variant_id):
return run_command(f"bin/gamesman getstart {game_name} {variant_id}")
@app.route("/<game_name>/<variant_id>/<position>")
def query(game_name, variant_id, position):
return run_command(f"bin/gamesman query -- {game_name} {variant_id} {position}")
if __name__ == "__main__":
from waitress import serve
serve(app, host="0.0.0.0", port=8084)