-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathneti_http_server.py
44 lines (38 loc) · 1.33 KB
/
neti_http_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
import ConfigParser
import time
import cgi
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from src.neti_neti_trainer import NetiNetiTrainer
from src.neti_neti import NetiNeti
config = ConfigParser.ConfigParser()
config.read('config/neti_http_config.cfg')
HOST = config.get('http_settings', 'host')
PORT = int(config.get('http_settings', 'port'))
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200, 'OK')
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('hello world')
def do_POST(self):
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE': self.headers['Content-Type'],
})
self.send_response(200)
self.end_headers()
self.wfile.write(nn.find_names(form['data'].value))
return
def run(server_class=HTTPServer,
handler_class=MyHandler):
server_address = (HOST, PORT)
print('Starting server, use <Ctrl-C> to stop')
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
if __name__ == '__main__':
print "Running NetiNeti Training, it might take a while..."
nnt = NetiNetiTrainer()
nn = NetiNeti(nnt)
run()