-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge json to one.py
51 lines (41 loc) · 1.11 KB
/
merge json to one.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
import glob
import json
import _sqlite3
def start(dir_path):
dir_files = glob.glob(dir_path + '*json')
list_collection = []
list_collection_m = {}
dir_files.sort()
for file in dir_files:
with open(file) as f:
data = json.load(f)
len_data = len(data)
i = 0
while i < len_data:
list_collection.append(data[str(i)])
i = i + 1
j = 0
for l in list_collection:
list_collection_m[str(j)] = l
j = j + 1
with open('merged' + '.json', 'w') as js:
json.dump(list_collection_m, js)
conn = _sqlite3.connect('merged.db')
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS terms(
term TEXT,
definition TEXT
)
""")
k = 0
for m in list_collection:
to_write = (m['term'], m['definition'])
c.execute("""
INSERT INTO terms VALUES (?,?)
""", to_write)
conn.commit()
conn.close()
if __name__ == '__main__':
fp = '/run/media/razein/internal_hdd/Projects/Git_Projects/Laws/Acts in India/Legal Terms/'
start(fp)