-
Notifications
You must be signed in to change notification settings - Fork 0
/
eliza.py
43 lines (34 loc) · 815 Bytes
/
eliza.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
import flask, flask.views
import matcher as matcher
app = flask.Flask(__name__)
app.secret_key = "bacon"
count = -2
def incr():
global count
count = count + 1
return count
class View(flask.views.MethodView):
def get(self):
return flask.render_template('index.html')
def post(self):
result = flask.request.form['expression']
count = incr()
if count == 0:
res = matcher.hi_eliza(result)
flask.flash(res)
count = incr()
print count
elif count > 1 and count < 20:
res = matcher.main(result)
flask.flash(res)
count = incr()
print count
elif count >= 20:
res = matcher.stop_eliza()
flask.flash(res)
count = incr()
print count
return self.get()
app.add_url_rule('/', view_func=View.as_view('main'), methods=['GET', 'POST'])
app.debug = True
app.run()