-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
36 lines (28 loc) · 916 Bytes
/
script.py
File metadata and controls
36 lines (28 loc) · 916 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
32
33
34
35
36
import csv
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument("file_path")
parser.add_argument("table_name")
args = parser.parse_args()
print(args.file_path)
with open(args.file_path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
result = ""
for row in csv_reader:
closure_sym = "'"
if line_count == 0:
closure_sym = "`"
result = "INSERT INTO " + args.table_name
result = result + "("
for val in row:
result = result + closure_sym + val + closure_sym + ","
result = result[:-1] + "),\n"
if line_count == 0:
result = result[:-2] + " VALUES\n "
line_count += 1
file = open(str(time.time()) + "-insert_query.sql", "w")
file.write(result[:-2])
file.close()
print ("SQL file created.. check insert_query.sql")