forked from schinken/py-webrelais
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy-webrelais.py
61 lines (41 loc) · 1.19 KB
/
py-webrelais.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
__author__ = 'schinken'
from parport import Parport
from flask import Flask, render_template,jsonify
app = Flask(__name__)
pp = Parport()
@app.route("/")
def page_main():
return render_template('index.html')
@app.route("/ports", methods=["GET"])
def get_ports():
return jsonify( response=pp.getPins() )
@app.route("/ports/<int:number>", methods=["GET"])
def get_port(number):
try:
return jsonify( response=pp.getPin( number ) )
except Exception:
return Exception.message, 404
@app.route("/ports", methods=["POST"])
def set_ports():
pp.setPins()
return jsonify( response=True )
@app.route("/ports/<int:number>", methods=["POST"])
def set_port(number):
try:
pp.setPin( number )
return jsonify( response=True )
except Exception:
return Exception.message, 404
@app.route("/ports", methods=["DELETE"])
def reset_ports():
pp.resetPins()
return jsonify( response=True )
@app.route("/ports/<int:number>", methods=["DELETE"])
def reset_port(number):
try:
pp.resetPin( number )
return jsonify( response=True )
except Exception:
return Exception.message, 404
if __name__ == '__main__':
app.run()