1.添加数据支持。

This commit is contained in:
facat 2019-06-18 18:18:53 +08:00
parent e20940de1f
commit 6204d44c8b
1 changed files with 11 additions and 6 deletions

17
main.py
View File

@ -1,17 +1,22 @@
from socketserver import BaseRequestHandler, TCPServer
import db
class EchoHandler(BaseRequestHandler):
def handle(self):
print("Got connection from", self.client_address)
host=self.request.recv(1024)
host = self.request.recv(1024)
print("Host is {host}".format(host=host))
if host:
if host=='bwg'.encode('ascii'):
self.request.sendall("50%\n".encode('ascii'))
print('send to bwg')
if host=='hosteons'.encode('ascii'):
self.request.sendall("80%\n".encode('ascii'))
latest_speed_dic = db.get_latest_speed()
for server in latest_speed_dic:
if host == server.encode("ascii"):
speed = int(server["speed"])
self.request.sendall(
"{weight}%\n".format(weight=speed).encode("ascii")
)
print("send to bwg with wight {weight}".format(weight=speed))
break
self.request.close()