-
Notifications
You must be signed in to change notification settings - Fork 0
/
disloc_service_API.py
76 lines (56 loc) · 1.71 KB
/
disloc_service_API.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
67
68
69
70
71
72
73
74
75
76
"""
disloc_service_API.py
-- a minimum flask api wrapper
$export FLASK_APP=disloc_service_API.py
$export FLASK_DEBUG=1
$python3 -m flask run
http://localhost:5000/gpsservice/test
"""
import sys
import socket
import json
from flask import Flask
from flask import request
from flask import Response
from flask import jsonify
from disloc_exec import dislocworkflow
app = Flask(__name__)
"""test service is running"""
@app.route("/dislocservice/test")
def test():
info={}
info["python"] = sys.version
info["runningmode"] = app.debug
info_str = info["python"] + " debug mode: "+str(info["runningmode"]) + "<p>"
info_str += disloc.__doc__.replace('\n','<br>')
return info_str
"""disloc service"""
@app.route("/dislocservice/disloc")
def disloc():
""" disloc service
/dislocservice/disloc?
Parameters:
--------------
input: emebed input file
inputurl: url of input file
optional:
output: name of output file
elevation: in degrees, default: 60
azimuth: in degrees, default: 0
radarfrequency: in GHz, default: 1.26
Returns:
--------------
json:
"""
args = request.args
# assume everything is right
if not("input" in args or 'inputurl' in args):
return Response(jsonify({"status":"failed","error": "input or inputurl required!"}),status=400)
result = dislocworkflow(args)
if result['status'] != 'success':
return Response(jsonify(result),status=500)
return jsonify(result)
if __name__ == "__main__":
pass
# old method
#app.run(host='0.0.0.0', debug=False)