forked from lmzach09/Python_ChatBot_Google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
27 lines (23 loc) · 837 Bytes
/
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
import http.server
import socketserver
from google_search import chatbot_query
PORT = 8080
DIRECTORY = 'public'
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)
def do_POST(self):
self.send_response(200)
content_length = int(self.headers['Content-Length'])
post_body = self.rfile.read(content_length)
self.end_headers()
print('user query', post_body)
google_search_chatbot_reply = chatbot_query(post_body)
self.wfile.write(str.encode(google_search_chatbot_reply))
with socketserver.TCPServer(('', PORT), Handler) as httpd:
print('serving at port', PORT)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()