From 8fcdb01b94b1a0cbb185ed81ca6a464607265794 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 24 Feb 2020 21:28:37 +0100 Subject: Regex support --- assets/web.js | 4 +++- dicofr.py | 17 +++++++++++++++++ web.py | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/assets/web.js b/assets/web.js index 46b6810..7b9bce5 100644 --- a/assets/web.js +++ b/assets/web.js @@ -23,7 +23,9 @@ const web = new Vue({ response.arrayBuffer().then(res => { this.definitions = msgpack.decode(new Uint8Array(res)); if( this.definitions && this.definitions[0] && this.definitions[0].mot) { - this.word = this.definitions[0].mot; + if(!this.word.includes('_')) { + this.word = this.definitions[0].mot; + } } }); } diff --git a/dicofr.py b/dicofr.py index 6c2042c..96f814c 100755 --- a/dicofr.py +++ b/dicofr.py @@ -24,6 +24,23 @@ def get_def_sql(word): }, res)) +def get_def_sql_reg(word): + with sqlite3.connect("result_all.sql") as con: + cur = con.cursor() + data = (word, ) + cur.execute('''SELECT * FROM entry WHERE word LIKE ?''', data) + + res = cur.fetchall() + return list(map(lambda w: {'mot': w[0], + 'cat-gram': w[1], + 'API': w[2], + 'infos': w[3].split("\t"), + 'genre': w[4], + 'accord': w[5], + 'def': msgpack.unpackb(w[6], raw=False), + }, res)) + + if __name__ == '__main__': if len(sys.argv) < 2: diff --git a/web.py b/web.py index 4ed0f98..c5e0b1c 100644 --- a/web.py +++ b/web.py @@ -22,11 +22,27 @@ app.config.from_object(__name__) 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) -- cgit v1.2.3