-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (26 loc) · 1.08 KB
/
Copy pathserver.py
File metadata and controls
31 lines (26 loc) · 1.08 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
import http.server # Our http server handler for http requests
import socketserver # Establish the TCP Socket connections
import os
import webbrowser
from move_coord import cube_from_scramble
import solver
PORT = 8080
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
def set_headers(self):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Content-type', 'application/json')
self.end_headers()
def do_GET(self):
if self.path.startswith("/solve"):
self.set_headers()
num_move = self.path[6:]
num_move = num_move.replace("_", " ") # replace with space
init_cube = cube_from_scramble(num_move, numeric_scramble=True)
solution = solver.solve(init_cube)
solution = ",".join(map(str, solution))
self.wfile.write(solution.encode())
with socketserver.TCPServer(("", PORT), MyHttpRequestHandler) as httpd:
print("http at port", PORT)
# webbrowser.open_new_tab("interface/index.html")
httpd.serve_forever()