-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
executable file
·42 lines (34 loc) · 1.22 KB
/
server.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
#!/usr/bin/env python
from flask import Flask
from flask import request
from sink import Sink
from flask.ext.httpauth import HTTPBasicAuth
from matrix import Matrix
import sys
if len(sys.argv) == 0:
# use Unicorn HAT when started without parameters
from RealHat import RealHat
hat = RealHat()
else:
# just show the matrix status on the console when started with one parameter
from FakeHat import FakeHat
hat = FakeHat()
#################################################################################
app = Flask(__name__)
auth = HTTPBasicAuth()
app.debug = True
led = Matrix(hat)
sink = Sink(led)
# http post http://127.0.0.1:5500/update status:='["NONE","BUILDING","OK","ERROR","NONE","WHAT?"]' --auth giveme:someled
# win: http post http://giveme:[email protected]:5500/update status:="[\"NONE\",\"BUILDING\",\"OK\",\"ERROR\",\"NONE\",\"WHAT?\"]"
@app.route("/update",methods=['POST'])
@auth.login_required
def update():
content = request.get_json(silent=True)
status = content['status']
return str(sink.put(status))
@auth.verify_password
def verify_password(username, password):
return username=='giveme' and password=='someled'
if __name__ == "__main__":
app.run(host='0.0.0.0',port=5500)