-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_records.py
More file actions
52 lines (38 loc) · 1.25 KB
/
insert_records.py
File metadata and controls
52 lines (38 loc) · 1.25 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
51
52
"""
Record insertion script.
Wrapper script to run record insertion script inbatch of 10000 records to avoid
the import script consuming too much memory.
"""
import sys
import os
from util import timeit
MAX_BATCH_SIZE = 10000
@timeit
def import_data():
"""Import Data."""
records_imported = 0
cmd = 'python3 main.py ' + ' '.join([sys.argv[1], sys.argv[2]])
total_records = int(sys.argv[3])
start_record = 1
if len(sys.argv) > 4:
start_record = int(sys.argv[4])
while records_imported < total_records:
batch_size = total_records - records_imported
if batch_size > MAX_BATCH_SIZE:
batch_size = MAX_BATCH_SIZE
final_cmd = "%s %i %i" % (cmd, batch_size, start_record)
print("executing: " + final_cmd)
exit_code = os.system(final_cmd)
if 0 == exit_code:
records_imported += batch_size
else:
print("Error: command returned non-zero status")
sys.exit(1)
start_record += batch_size
return records_imported
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: %s action [parameters]" % sys.argv[0])
sys.exit(1)
rec_count = import_data()
print("Finished! %i records inserted." % rec_count)