aboutsummaryrefslogtreecommitdiff
path: root/msgPack2sqlite_msgPack.py
diff options
context:
space:
mode:
Diffstat (limited to 'msgPack2sqlite_msgPack.py')
-rw-r--r--msgPack2sqlite_msgPack.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/msgPack2sqlite_msgPack.py b/msgPack2sqlite_msgPack.py
new file mode 100644
index 0000000..b77dd2e
--- /dev/null
+++ b/msgPack2sqlite_msgPack.py
@@ -0,0 +1,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])
+