-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
66 lines (49 loc) · 1.43 KB
/
web.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from cerberus import Validator
from flask import Flask, request
from flask_cors import CORS
from main import two_D_to_three_D
from utils import env_is_local
app = Flask(__name__)
if env_is_local():
print("Authorising CORS for local env")
cors = CORS(app)
@app.route("/health-check", methods=['GET'])
def health_check():
return {'msg': 'ok'}
@app.route("/version", methods=['GET'])
def get_version():
return {'version': 1.0}
raw_a_shape_projection_schema = {
'type': 'dict',
'require_all': True,
'schema': {
'type': {
'type': 'string',
'allowed': ['polygon'],
},
'vertices': {
'type': 'dict',
'keysrules': {'type': 'string'},
'allow_unknown': True,
},
'edges': {
'type': 'dict',
'keysrules': {'type': 'string'},
'allow_unknown': True,
},
}
}
raw_two_D_schema = {
'xy': raw_a_shape_projection_schema,
'xz': raw_a_shape_projection_schema,
'yz': raw_a_shape_projection_schema,
}
validator_reconstruct = Validator(raw_two_D_schema)
@app.route("/reconstruct", methods=['POST'])
def reconstruct():
parsed_payload = request.get_json()
if not validator_reconstruct.validate(parsed_payload):
return validator_reconstruct.errors, 400
return two_D_to_three_D(parsed_payload)
if __name__ == '__main__' and env_is_local():
app.run(debug=True, port=8000)