blob: c5e0b1c8f5db98e69b82f7b6a94324472b381e79 (
plain)
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
|
from flask import Flask, request, Response, send_file
import msgpack
# from flask_cors import CORS
import dicofr
# configuration
DEBUG = False
# instantiate the app
app = Flask(__name__,
static_url_path='',
static_folder='assets')
app.config.from_object(__name__)
# enable CORS
# CORS(app, resources={r'/*': {'origins': '*'}})
@app.route('/', methods=['GET'])
def index_client():
return send_file("index.html", mimetype='text/html')
def get_def_reg(w):
if res := dicofr.get_def_sql_reg(w):
return msgpack.packb(res)
# Recherche du mot en minuscule
elif res := dicofr.get_def_sql_reg(w.lower()):
return msgpack.packb(res)
# Recherche du mot en nom propre
elif res := dicofr.get_def_sql_reg(w.title()):
return msgpack.packb(res)
else:
return Response("", status=404)
@app.route('/def', methods=['GET'])
def get_def():
w = request.args.get('w')
if '_' in w:
return get_def_reg(w);
# Recherche du mot tapΓ©
if res := dicofr.get_def_sql(w):
return msgpack.packb(res)
# Recherche du mot en minuscule
elif res := dicofr.get_def_sql(w.lower()):
return msgpack.packb(res)
# Recherche du mot en nom propre
elif res := dicofr.get_def_sql(w.title()):
return msgpack.packb(res)
else:
return Response("", status=404)
return Response(msgpack.packb(request.args.get('w')),
mimetype='application/msgpack')
if __name__ == '__main__':
app.run()
|