diff options
author | ache <ache@ache.one> | 2020-02-24 21:28:37 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2020-02-24 21:28:37 +0100 |
commit | 8fcdb01b94b1a0cbb185ed81ca6a464607265794 (patch) | |
tree | f5fb9d448c53052f47173f06065bb3ad9ba3d039 | |
parent | Format fix (diff) |
Regex support
-rw-r--r-- | assets/web.js | 4 | ||||
-rwxr-xr-x | dicofr.py | 17 | ||||
-rw-r--r-- | web.py | 16 |
3 files changed, 36 insertions, 1 deletions
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; + } } }); } @@ -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: @@ -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) |