aboutsummaryrefslogtreecommitdiff
path: root/dicofr.py
blob: 6c2042c5ff92b80e8e445f6a9820525bfddb7def (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
#!/bin/env python
# To load with python interpreter

import msgpack
import ui
import sqlite3
import sys


def get_def_sql(word):
    with sqlite3.connect("result_all.sql") as con:
        cur = con.cursor()
        data = (word, )
        cur.execute('''SELECT * FROM entry WHERE word = ?''', 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:
      print("Erreur: Rechercher un mot", file=sys.stderr)
      exit()

    for w in get_def_sql(sys.argv[1]):
        ui.show_terminal(w)