forked from denysvitali/presentation-clicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (34 loc) · 916 Bytes
/
main.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
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.resource import Resource
from subprocess import call
keys = {
b'n': 'Page_Down',
b'p': 'Page_Up',
}
def run_action(message):
print("Got ", message)
key = keys.get(message, None)
if key:
call(['xdotool', 'key', key])
def home():
return open("./index.html", 'rb').read()
def next_button():
run_action(b'n')
return b"ok"
def prev_button():
run_action(b'p')
return b"ok"
class CallResource(Resource):
def __init__(self, fun):
Resource.__init__(self)
self.fun = fun
def render_GET(self, request):
return self.fun()
root = Resource()
root.putChild(b'', CallResource(home))
root.putChild(b'next', CallResource(next_button))
root.putChild(b'prev', CallResource(prev_button))
site = Site(root)
reactor.listenTCP(8080, site)
reactor.run()