Init get_color
This commit is contained in:
parent
3ad7d6f6fc
commit
16930a2770
22
main.py
22
main.py
@ -8,6 +8,11 @@ import time
|
|||||||
global LTIME
|
global LTIME
|
||||||
LTIME = cur_time = time.monotonic()
|
LTIME = cur_time = time.monotonic()
|
||||||
|
|
||||||
|
def kbv(dict_, value):
|
||||||
|
for i in dict_:
|
||||||
|
if dict_[i] == value:
|
||||||
|
return i
|
||||||
|
|
||||||
class RequestHandler(BaseHTTPRequestHandler):
|
class RequestHandler(BaseHTTPRequestHandler):
|
||||||
MATRIX_SIZE = (800, 1024)
|
MATRIX_SIZE = (800, 1024)
|
||||||
COLORS = {
|
COLORS = {
|
||||||
@ -18,6 +23,21 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
params = parse_qs(self.path[2:])
|
||||||
|
if 'get_color' in params:
|
||||||
|
x, y = map(int, params['get_color'][0].split(','))
|
||||||
|
matrix = self.get_matrix()
|
||||||
|
color = matrix[x][y]
|
||||||
|
|
||||||
|
#Magic~~~
|
||||||
|
color = tuple(list(map(int, str(color)[1:-1].split())))
|
||||||
|
color = kbv(self.COLORS, color)
|
||||||
|
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-type', 'text/plain')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(f'{color}'.encode())
|
||||||
|
else:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'image/png')
|
self.send_header('Content-type', 'image/png')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
@ -32,7 +52,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||||||
address = self.client_address[0]
|
address = self.client_address[0]
|
||||||
print("IP: ", address)
|
print("IP: ", address)
|
||||||
|
|
||||||
if cur_time - LTIME <= 0.01:
|
if cur_time - LTIME <= 0.005:
|
||||||
self.send_error(429, 'Too Many Requests')
|
self.send_error(429, 'Too Many Requests')
|
||||||
self.send_response(429)
|
self.send_response(429)
|
||||||
return 0
|
return 0
|
||||||
|
4
post.py
4
post.py
@ -4,3 +4,7 @@ payload = {'x': 52, 'y': 20, 'color': 'r'}
|
|||||||
#response = requests.post('http://pb.dmcraft.online', data=payload)
|
#response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
response = requests.post('http://127.0.0.1:3333', data=payload)
|
response = requests.post('http://127.0.0.1:3333', data=payload)
|
||||||
print(response)
|
print(response)
|
||||||
|
|
||||||
|
#Get color
|
||||||
|
response = requests.get('http://127.0.0.1:3333/?get_color=52,20')
|
||||||
|
print(response.text)
|
||||||
|
Loading…
Reference in New Issue
Block a user