-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (47 loc) · 1.73 KB
/
app.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
58
59
60
61
62
63
64
65
from flask import Flask, render_template, request
from flask_bootstrap import Bootstrap
from flask_appconfig import AppConfig
from flask_wtf import Form, RecaptchaField
from wtforms import TextField, HiddenField, ValidationError, RadioField, BooleanField, SubmitField
from wtforms.validators import Required
import re
import gevent.monkey
from gevent.pywsgi import WSGIServer
gevent.monkey.patch_all()
from give_answer import answer_question
import unicodedata
import wolframalpha
import wikipedia
class ExampleForm(Form):
question = TextField('', description='', validators=[Required()])
submit_button = SubmitField('Go')
def create_app(configfile=None):
app = Flask(__name__)
AppConfig(app, configfile)
Bootstrap(app)
app.config['SECRET_KEY']= ## insert your secret key
@app.route('/', methods=('GET', 'POST'))
def index():
if request.method == 'POST':
try:
question = request.form['question']
except KeyError, e:
print 'key eroor'
print 'I got a KeyError - reason "%s"' % str(e)
except:
print 'I got another exception, but I should re-raise'
raise
print(question)
answer = answer_question(question)
print 'answer: ',answer
answer=re.sub('([(].*?[)])',"",answer)
return render_template('answer.html', answer=answer, question=question)
form = ExampleForm()
return render_template('index.html', form=form)
return app
# create main callable
app = create_app()
if __name__ == '__main__':
http_server = WSGIServer(('127.0.0.1', 9191), app)
print("starting server on port 9191")
http_server.serve_forever()