-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmksqlitedb.py
More file actions
31 lines (23 loc) · 841 Bytes
/
mksqlitedb.py
File metadata and controls
31 lines (23 loc) · 841 Bytes
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
#!/usr/bin/env python3
import sqlite3
from sys import argv
import subprocess
# NB create the index after import, or you'll have a slow time
print(f'[-] Creating database {argv[1]} from CSV file {argv[2]}')
with sqlite3.connect(argv[1]) as db:
cur = db.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS hashes \
(twobytes TEXT NOT NULL COLLATE NOCASE,\
chunk1 TEXT NOT NULL COLLATE NOCASE,\
chunk2 TEXT NOT NULL COLLATE NOCASE);\
')
cur.execute('DROP INDEX IF EXISTS tb;')
print('[-] Starting import, this can take a long time if the CSV is large')
subprocess.call(["sqlite3", argv[1],
".mode csv",
f'.import {argv[2]} hashes'])
print('[-] Creating index ...')
with sqlite3.connect(argv[1]) as db:
cur = db.cursor()
cur.execute('CREATE INDEX IF NOT EXISTS tb ON hashes (twobytes);')
print('[+] All done')