aboutsummaryrefslogtreecommitdiff
path: root/msgPack2sqlite_msgPack.py
blob: b77dd2e30e4f658d7df6e67bdd209adfb41f1828 (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
# To load with python interpreter

import msgpack
import ui

import sqlite3

with open('result_all.pack', 'rb') as f:
    r = f.read()

d = p = msgpack.unpackb(r, raw=False)
del r

with sqlite3.connect("result_all.sql") as con:
    cur = con.cursor()
    cur.execute('''CREATE TABLE IF NOT EXISTS entry (
        word TEXT,
        cat_gram TEXT,
        API TEXT,
        infos TEXT,
        genre TEXT,
        accord TEXT,
        defs BLOG,
        ID INTEGER PRIMARY KEY)''')
    con.commit()

    for w, listW in d.items():
        for word in listW:
            data = (w, word['cat-gram'], word['API'], "\t".join(word['infos']),
                    word['genre'], word['accord'],
                    msgpack.packb(word['def']))
            cur.execute('''INSERT INTO entry (word, cat_gram, API, infos,
            genre, accord, defs) VALUES (?, ?, ?, ?,  ?, ?,  ?)''', data)
    con.commit()


def give_def(w):
    ui.show_terminal(d[w])