-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
76 lines (62 loc) · 1.86 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from flask import *
import dict
app = Flask(__name__)
@app.route('/search')
def search():
word = request.args.get('word')
item = dict.searchWord(word)
if(item):
mean = item['meanings']
sen = item['examples']
return render_template('wordinfo.html', w = word,\
meaning = mean, examples = sen)
return ''
@app.route('/edit')
def edit():
word = request.args.get('word')
num = request.args.get('num')
item = dict.searchWord(word)
if(item):
sen = item['examples'][int(num)-1]
return render_template('edit.html', en = sen['sentence'],\
ch = sen['translation'], i = int(num))
return ''
@app.route('/addsen_t')
def addsen_t():
return render_template('add.html')
@app.route('/delsen', methods=['POST'])
def delsen():
word = request.form['word']
num = request.form['num']
n = int(num) - 1
item = dict.searchWord(word)
del item['examples'][n]
return dict.modifyWord(item)
@app.route('/addsen', methods=['POST'])
def addsen():
word = request.form['word']
en = request.form['en']
ch = request.form['ch']
item = dict.searchWord(word)
item['examples'].append({'sentence':en, 'translation': ch})
return dict.modifyWord(item)
@app.route('/modifysen', methods=['POST'])
def modifysen():
word = request.form['word']
num = request.form['num']
en = request.form['en']
ch = request.form['ch']
item = dict.searchWord(word)
item['examples'][int(num) - 1]['sentence'] = en
item['examples'][int(num) - 1]['translation'] = ch
return dict.modifyWord(item)
@app.route('/typeahead')
def typeahead():
s = request.args.get('query')
return dict.suggestWord(s)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
# app.debug = True
app.run(host='0.0.0.0')