-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.py
48 lines (41 loc) · 1.45 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
43
44
45
46
47
48
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from spells import Spells
class myHandler(BaseHTTPRequestHandler):
# Handler for the GET requests
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
# Send the html message
if (self.path == "/circle"):
spells.cast("circle")
if (self.path == "/square"):
spells.cast("square")
if (self.path == "/zee"):
spells.cast("zee")
if (self.path == "/eight"):
spells.cast("eight")
if (self.path == "/triangle"):
spells("triangle")
if (self.path == "/tee"):
spells.cast("tee")
if (self.path == "/left"):
spells.cast("left")
if (self.path == "/center"):
spells.cast("center")
self.wfile.write(bytes("{'done':true}", "utf-8"))
return
def runServer():
import six.moves.SimpleHTTPServer
import six.moves.socketserver
PORT = 8000
try:
# Create a web server and define the handler to manage the
# incoming request
server = HTTPServer(('', PORT), myHandler)
print('Started httpserver on port ', PORT)
# Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down the web server')
server.socket.close()