-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_json_to_sqlite.py
executable file
·74 lines (58 loc) · 1.42 KB
/
convert_json_to_sqlite.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python2.7
import sqlite3, json
with open('dict-he-en.json') as data_file:
he_dict = json.load(data_file)
with open('dict-en-he.json') as data_file:
en_dict = json.load(data_file)
db = sqlite3.connect('milon.db')
c = db.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS android_metadata (
locale TEXT DEFAULT "en_US"
);
''')
c.execute('''
INSERT INTO android_metadata VALUES ("en_US")
''')
c.execute('''
CREATE TABLE IF NOT EXISTS he_word(
id INTEGER PRIMARY KEY,
translated TEXT,
translation TEXT,
part TEXT
)
''')
c.execute('''
CREATE TABLE IF NOT EXISTS en_word(
id INTEGER PRIMARY KEY,
translated TEXT,
translation TEXT,
part TEXT
)
''')
for w in he_dict:
translation = ''
for i, t in enumerate(w['translation']):
if not i == 0:
translation += ', '
translation += t
word = [
w['translated'],
translation,
w['part_of_speech']
]
c.execute('INSERT INTO he_word VALUES (NULL, ?, ?, ?)', word)
for w in en_dict:
translation = ''
for i, t in enumerate(w['translation']):
if not i == 0:
translation += ', '
translation += t
word = [
w['translated'],
translation,
w['part_of_speech']
]
c.execute('INSERT INTO en_word VALUES (NULL, ?, ?, ?)', word)
db.commit()
db.close()