-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
executable file
·60 lines (46 loc) · 1.58 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
#!/usr/bin/env python3
from flask import Flask, render_template, request, url_for, redirect, session
import execute
import languageprocess.sqlizer
import languageprocess.tokenizer
import sys
import os
#specify what belongs to application
app= Flask(__name__.split('.')[0])
app.secret_key = os.urandom(10)
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
'''application home page with search box'''
if request.method == 'POST':
query = request.form['query']
sampleinput = None
if request.form['input']:
sampleinput = request.form['input']
squery = languageprocess.sqlizer.sqlize(query, sampleinput)
#for exception rasied cases
if 'ERROR:' in squery:
result = str(squery)
session['result'] = result
return redirect(url_for('search', result = result))
s = execute.execi(squery)
global quer
quer = squery
if s:
result = str(s)
session['result'] = result
return redirect(url_for('search', result=result))
else:
result = str(s)
session['result'] = result
return redirect(url_for('search', result=result))
return render_template('index.html', title='NQL')
@app.route('/search', methods=['GET', 'POST'])
def search():
result = request.args['result']
result = session['result']
print(result)
return render_template('result.html', value=result)
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')