-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusdafood2sql.py
More file actions
executable file
·46 lines (33 loc) · 1.39 KB
/
Copy pathusdafood2sql.py
File metadata and controls
executable file
·46 lines (33 loc) · 1.39 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
#!/usr/bin/python3
'''
Created on Jun 13, 2020
@author: Matthias Jung
'''
from os import listdir
from os.path import isfile, join
import argparse
from helper import Helper
from sqliteimporter import SqliteImporter
# if you want to use mysql or pgsql
# from mysqlimporter import MysqlImporter
# from pgsqlimporter import PgsqlImporter
def _get_args():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', type=Helper.is_readable_dir, help='path to csv input folder', required=True)
# if you want to use mysql or pgsql an output file should not be a file, but rather a database uri or something similar
parser.add_argument('-o', '--output', type=Helper.not_is_file, help='path to sqlite output file', required=True)
parser.add_argument('-k', '--indices', action='store_true')
args = parser.parse_args()
return args
def main():
args = _get_args()
importer = SqliteImporter(args.output)
# if you want to use mysql or pgsql
# importer = MysqlImporter(user='', password='', host='', port='', database='')
# importer = PgsqlImporter(user='', password='', host='', port='', database='')
for file in listdir(args.input):
if isfile(join(args.input, file)) and file.endswith('.csv'):
importer.import_file('{0}/{1}'.format(args.input, file), args.indices)
importer.print_total_result()
if __name__ == '__main__':
main()