-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
34 lines (26 loc) · 935 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
30
31
32
33
34
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
from template import Template
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['POST'])
def result():
req = request.form.to_dict()
print(req)
template = Template(
hardware = req['hardware'],
num_leds = req['n_of_led'],
button_colors = req['color_of_buttons'],
num_buttons = req['n_of_buttons'],
sensor_boundary = req['ultrasonic_boundary'],
sensor_color1 = req['ultrasonic_color1'],
sensor_color2 = req['ultrasonic_color2'],
no_hardware_color = req['no_hardware_color']
)
code = template.synthesize_program()
response = jsonify({'code': code})
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Content-Type', 'application/json')
return response
if __name__ == '__main__':
app.run(port=8000, debug=True)