forked from greentangerine/ME3000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsofar.py
More file actions
executable file
·60 lines (47 loc) · 1.38 KB
/
Copy pathsofar.py
File metadata and controls
executable file
·60 lines (47 loc) · 1.38 KB
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
from flask import Flask, render_template
import sys
sys.path.insert(0, '/home/pi/ME3000')
import me3000 as me
app = Flask(__name__)
THRESHOLD_FILE="/home/pi/ME3000/pct.txt"
def read_threshold():
try:
tfile = open(THRESHOLD_FILE, "r")
threshold = int(tfile.readline().split("=")[-1])
tfile.close()
except:
threshold = -1
return threshold
def write_threshold(pctval):
if pctval >=20 and pctval <= 100:
try:
ostr = "THRESHOLD=" + str(pctval)
print(ostr)
tfile = open(THRESHOLD_FILE, "w")
tfile.write(ostr)
tfile.close()
return pctval
except:
return -1
else:
return -1
@app.route('/')
def index():
return render_template('index.html')
@app.route('/pct/')
@app.route('/pct/<int:pct_val>')
def set_pct(pct_val=None):
if pct_val == None:
retval = read_threshold()
if retval != -1:
return render_template('pct.html', opstr="Current", pctval=retval)
else:
return render_template('error.html'), 500
else:
retval = write_threshold(pct_val)
if retval != -1:
return render_template('pct.html', opstr="New", pctval=retval)
else:
return render_template('error.html'), 500
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')