-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
32 lines (24 loc) · 1.01 KB
/
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
# from doser import Doser
from doser import Doser
from http.server import(BaseHTTPRequestHandler, HTTPServer)
import json
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
config = json.loads(open('./secrets.json').read())
stop_words = [line.rstrip('\n') for line in open('./french_stop_words.txt')]
swear_words = [line.rstrip('\n') for line in open('./french_swear_words.txt')]
doser = Doser(config['file'], config['people'], stop_words, swear_words)
message = json.dumps(doser.parse())
self.wfile.write(bytes(message, 'utf8'))
return
def run():
print('Starting server...')
server_address = ('127.0.0.1', 3003)
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
print('Running server...')
httpd.serve_forever()
run()