-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_db_to_one.py
More file actions
50 lines (39 loc) · 1.08 KB
/
Copy pathmulti_db_to_one.py
File metadata and controls
50 lines (39 loc) · 1.08 KB
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
import glob
import os
import sqlite3
def multi_to_one(fp, db):
dir_list = glob.glob(fp + "*.db")
conn = sqlite3.connect("./" + db)
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS central_acts (
act_name TEXT,
is_downloaded INT,
is_bookmarked INT,
act_data BLOB
)
""")
conn.commit()
to_write = []
sorted_dir_list = sorted(dir_list)
for dir in sorted_dir_list:
name = os.path.basename(dir).replace('.db', '')
blob = convert_to_binary_data(dir)
to_write.append((
name,
1,
0,
blob
))
c.executemany("INSERT INTO central_acts VALUES (?,?,?,?)", to_write)
conn.commit()
conn.close()
def convert_to_binary_data(filename):
# Convert digital data to binary format
with open(filename, 'rb') as file:
blobData = file.read()
return blobData
if __name__ == '__main__':
file_path = "./Database/"
db_name = "Laws of India"
multi_to_one(file_path, db_name)