-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sample.py
More file actions
43 lines (34 loc) · 1.02 KB
/
create_sample.py
File metadata and controls
43 lines (34 loc) · 1.02 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
import sys
import argparse
import sqlite3
def main(path_to_db, path_to_sample, nb_samples):
connection_sample = sqlite3.connect(path_to_sample)
cursor_sample = connection_sample.cursor()
cursor_sample.execute('''
ATTACH DATABASE ? AS full_db
''', [path_to_db])
cursor_sample.execute('''
CREATE TABLE May2015 AS
SELECT *
FROM full_db.May2015
LIMIT ?
''', [nb_samples])
connection_sample.commit()
connection_sample.close()
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
"path_to_db",
help="Path to the whole database file",
)
arg_parser.add_argument(
"path_to_sample",
help="Path to the sample database file to create",
)
arg_parser.add_argument(
"nb_samples",
type=int,
help="Number of rows to sample",
)
args = vars(arg_parser.parse_args())
main(args['path_to_db'], args['path_to_sample'], args['nb_samples'])