-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_server.py
More file actions
42 lines (32 loc) · 1.14 KB
/
http_server.py
File metadata and controls
42 lines (32 loc) · 1.14 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
class ServerHandle(BaseHTTPRequestHandler):
blink = None
def __init__(self, request, client_address, server):
BaseHTTPRequestHandler.__init__(self, request, client_address, server)
def _set_response(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self._set_response()
self.wfile.write("GET request for {}".format(self.path).encode('utf-8'))
if self.path == "/blink":
self.play_notification()
self.blink.blink_pattern((0, 170, 85,), 500, 0.5)
@staticmethod
def play_notification():
f = '0745.wav'
subprocess.Popen(['aplay', '-q', 'wav/' + f])
class Server(object):
def __init__(self, blink):
ServerHandle.blink = blink
server_address = ('', 9996)
httpd = HTTPServer(server_address, ServerHandle)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()