File size: 870 Bytes
20b0e66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, request, render_template

from api import (
	get_definition,
	get_translation,
	get_image,
)


app = Flask(__name__)

@app.route('/')
def index():
	word = request.args.get('word', None)

	# HOME PAGE NO WORD YET
	if word == None:
		return render_template("index.html", data=None)

	# 1. GET DEFINITION
	print("-------> get_definition")
	word, english, meanings_examples = get_definition(word)

	# 2. GET TRANSLATION
	print("-------> get_translation")
	if not english:
		english = get_translation(word)

	# 3. GET IMAGE
	print("-------> get_image")
	img = get_image(english)

	print("-------> return_data")
	# 4. RETURN DATA
	data = {
		"word": word,	
		"english": english,
		"img": img,	
		"meanings_examples": meanings_examples,	
	}
	return render_template("index.html", data=data)

if __name__ == '__main__':
	app.run(debug=True)
	# app.run()