forked from sengupta/twss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
twss_server.py
57 lines (45 loc) · 1.08 KB
/
twss_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
45
46
47
48
49
50
51
52
53
54
55
56
57
import web
import json
import twsslib
from web import form
render = web.template.render('templates/')
myform = form.Form(
form.Textbox('query'),
)
urls = (
'/train/(.*)', 'train',
'/query/(.*)', 'query',
'/', 'index',
)
app = web.application(urls, globals())
twss = twsslib.TextClassifier()
try:
twss.load()
except:
twss.train()
twss.save()
class query:
def GET(self, text):
return 'Not implemented yet.'
class query:
def GET(self, text):
try:
return json.dumps(twss.is_positive(text))
except:
return json.dumps(False)
class index:
def GET(self):
form = myform()
return render.inputform(form=form, istwss=None)
def POST(self):
form = myform()
if not form.validates():
return render.inputform(form)
else:
try:
istwss = twss.is_positive(form.query.value)
except:
istwss = False
return render.inputform(form=form, istwss=istwss)
if __name__ == '__main__':
app.run()