You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
661 B
Python
30 lines
661 B
Python
from flask import Flask, request, abort
|
|
import json
|
|
|
|
app = Flask(__name__)
|
|
|
|
import simulation
|
|
|
|
@app.route("/", methods=['GET', 'POST'])
|
|
def index():
|
|
if request.method != 'POST' or not request.data:
|
|
return abort(400);
|
|
|
|
params = json.loads(request.data.decode(encoding='utf-8'))
|
|
pos = params['pos']
|
|
direction = params['dir']
|
|
|
|
if len(pos) > 10 or direction not in (0, 225, 270, 315):
|
|
return abort(400);
|
|
|
|
ws, pot = simulation.run(direction, pos);
|
|
return {
|
|
'pos': pos,
|
|
'ws': ws,
|
|
'pot': pot,
|
|
'dir': direction,
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host='localhost', port='1234')
|