-
Notifications
You must be signed in to change notification settings - Fork 0
/
berryGrowServer.py
executable file
·59 lines (43 loc) · 1.5 KB
/
berryGrowServer.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
#!/usr/bin/python
from flask import *
import pprint
import json
import os
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
pathMachinesConf = CURRENT_PATH +'/conf/machinesConf.json'
pathMachinesStatus = CURRENT_PATH +'/conf/machinesStatus.json'
app = Flask(__name__, static_url_path='')
@app.route('/')
@app.route('/index')
def index():
with open( CURRENT_PATH + '/static/berrygrow.html', 'r') as content_file:
content = content_file.read()
return content
@app.route('/getStatus')
def getStatus():
return Response(open( pathMachinesStatus ).read(), mimetype='text/json')
@app.route('/getConf')
def getConf():
return Response(open( pathMachinesConf ).read(), mimetype='text/json')
@app.route('/setStatus', methods = ['POST'])
def setStatus():
json.dump( request.json, open( pathMachinesStatus, 'w' ) )
return Response(response= '{ "response": "" }',
status=200,
mimetype="application/json")
@app.route('/setConf', methods = ['POST'])
def setConf():
ret = 'true'
try:
jsonObj = json.load( request.form['confData'] )
except ValueError, e:
ret = '"Invalid JSON"'
else:
with open( pathMachinesConf , 'w') as outfile:
json.dump( jsonObj, outfile )
return Response(response= '{ "response": ' + ret + ' }',
status=200,
mimetype="application/json")
if __name__ == '__main__':
app.debug = True
app.run( host="0.0.0.0", port=5000 )