-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·38 lines (29 loc) · 1.08 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
#!/usr/bin/env python
#
# WebCamServer.py
# WebCamServer - Raspberry Pi Video Wall WebController
#
# Created by Jeremy Noonan on 10/12/2014
import SimpleHTTPServer, SocketServer
import urlparse
import camManager
PORT = 8080 # Change this if you wish to listen on a different port
class WebController (SimpleHTTPServer.SimpleHTTPRequestHandler):
mgr = camManager.camManager()
def do_GET(self):
# Parse query data
parsedParams = urlparse.urlparse(self.path)
queryParsed = urlparse.parse_qs(parsedParams.query)
# Add 'api' prefix to URL to perform commands
if parsedParams.path == "/api":
self.processRequest(queryParsed)
else:
# Default to serve up a local file
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self);
def processRequest(self, query):
# Send response then handle so we don't keep the browser waiting
self.send_response(200)
self.mgr.handleCommand(query);
httpd = SocketServer.TCPServer(("", PORT), WebController)
print "WebCamServer -- Listening on port", PORT
httpd.serve_forever()