-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
89 lines (71 loc) · 2.54 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import Flask,request,render_template,jsonify
import json
import model
#--------------------------------------------------------------------------------------
app = Flask(__name__)
#--------------------------------------------------------------------------------------
@app.route('/')
def index():
#print(request.method)
# if request.method == 'POST':
# search=request.form['search']
# if search == "":
# search = "++++++++++++++++++++++"
# links=model.getList(search)
# print(links)
# itemsFound = links.__len__()
return render_template("index.html")
#--------------------------------------------------------------------------------------
#for index ajax purpose
@app.route('/searchAJAX',methods=['GET'])
def process():
search=request.args["search"]
linkType = request.args["type"]
#print(search,linkType)
splt = search.split(" ")
search = []
for word in splt:
if word != "":
search.append(word)
if search[0] == "" or search[0] == "%":
return json.dumps({'error':'True'})
links=model.getList(search[0],linkType)
if links:
return jsonify(links)
else:
return jsonify({'error':'True'})
#--------------------------------------------------------------------------------------
#admin page only
@app.route('/admin/')
def admin():
return render_template("admin.html")
#--------------------------------------------------------------------------------------
#admin page ajax
@app.route('/adminAJAX',methods=['POST'])
def adminAJAX():
result = [{"status":"error","response":"Incorrect input"}]
return json.dumps(result)
#--------------------------------------------------------------------------------------
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'),404
#--------------------------------------------------------------------------------------
# @app.route('/name/<name>')
# def name(name):
# return 'Hey there %s ' % name
#--------------------------------------------------------------------------------------
# @app.route('/number/<int:num>')
# def number(num):
# num += 1
# return " %s " % num
#--------------------------------------------------------------------------------------
# @app.route('/testGetPost',methods=['GET','POST'])
# def testGetPost():
# if request.method == 'POST':
# return 'You are using POST method'
# else:
# return 'You are using GET method'
#--------------------------------------------------------------------------------------
if __name__ == '__main__':
app.run(debug=True)
#--------------------------------------------------------------------------------------