Add ability to generate necessary INSERTs
parent
35a9c8fbd9
commit
5a0d50116d
|
@ -0,0 +1,4 @@
|
||||||
|
Carnival,CRVL,http://www.carnival.com
|
||||||
|
Celebrity,CELB,http://www.celebritycruises.com
|
||||||
|
NCL,NCLC,http://www.ncl.com
|
||||||
|
Princess,PRCS,http://www.princess.com
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
1,Mexico,Miami,7,NCL,Norwegian Pearl,799.00
|
||||||
|
2,New England,Boston,7,NCL,Norwegian Jewel,895.75
|
||||||
|
3,ABC Islands,Miami,4,Celebrity,Equinox,450.50
|
||||||
|
4,Hawaii,San Francisco,14,Princess,Crown Princess,2310.00
|
||||||
|
5,Panama Canal,Miami,10,Carnival,Carnival Spirit,1432.99
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
1,'Dylan','Ward','42 Elm Place',8915367188,22
|
||||||
|
2,Austin,Ross,657 Redondo Ave.,1233753684,25
|
||||||
|
3,Lisa,Powell,5 Jefferson Ave.,6428369619,17
|
||||||
|
4,Brian,Martin,143 Cambridge Ave.,5082328798,45
|
||||||
|
5,Nicole,White,77 Massachusetts Ave.,6174153059,29
|
||||||
|
6,Tyler,Garcia,175 Forest St.,9864752346,57
|
||||||
|
7,Anna,Allen,35 Tremont St.,8946557732,73
|
||||||
|
8,Michael,Sanchez,9 Washington Court,1946825344,18
|
||||||
|
9,Justin,Myers,98 Lake Hill Drive,7988641411,26
|
||||||
|
10,Bruce,Clark,100 Main St.,2324648888,68
|
||||||
|
11,Rachel,Lee,42 Oak St.,2497873464,19
|
||||||
|
12,Kelly,Gray,1414 Cedar St.,9865553232,82
|
||||||
|
13,Madison,Young,8711 Meadow St.,4546667821,67
|
||||||
|
14,Ashley,Powell,17 Valley Drive,2123043923,20
|
||||||
|
15,Joshua,Davis,1212 8th St.,7818914567,18
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
1,12,1,2,'9-Nov-18'
|
||||||
|
2,14,4,5,'21-Jan-19'
|
||||||
|
3,5,4,1,'11-Dec-18'
|
||||||
|
4,9,5,4,'31-Aug-19'
|
||||||
|
5,13,1,2,'10-Apr-19'
|
||||||
|
6,5,4,6,'29-Jul-18'
|
||||||
|
7,2,2,2,'17-May-19'
|
||||||
|
8,4,1,10,'11-Apr-19'
|
||||||
|
9,10,5,3,'3-Jun-18'
|
||||||
|
10,5,3,9,'15-Oct-18'
|
||||||
|
11,1,2,7,'8-Mar-19'
|
||||||
|
12,5,4,7,'24-Nov-18'
|
||||||
|
13,8,1,1,'3-Aug-19'
|
||||||
|
14,15,5,10,'13-Dec-18'
|
||||||
|
15,4,3,7,'6-Feb-19'
|
||||||
|
16,6,4,5,'12-Aug-19'
|
||||||
|
17,14,2,8,'22-Jun-19'
|
||||||
|
18,11,5,9,'1-Feb-19'
|
||||||
|
19,7,4,8,'15-Mar-19'
|
||||||
|
20,14,4,3,'28-Feb-19'
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
1,Chloe,Rodriguez,Assistant,31750.00
|
||||||
|
2,Ben,Wilson,Agent,47000.22
|
||||||
|
3,Mia,Smith,Manager,75250.00
|
||||||
|
4,Noah,Williams,Assistant,32080.90
|
||||||
|
5,Liam,Brown,Manager,60500.75
|
||||||
|
6,Mason,Jones,Manager,79000.00
|
||||||
|
7,Olivia,Miller,Agent,54000.50
|
||||||
|
8,Sofia,Davis,Agent,45000.00
|
||||||
|
9,Jason,Garcia,Manager,52025.95
|
||||||
|
10,Emily,Johnson,Assistant,22000.50
|
||||||
|
11,Ethan,Elm,Agent,27044.52
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import glob
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
def is_num(val):
|
||||||
|
return val.replace('.', '', 1).isdigit()
|
||||||
|
|
||||||
|
|
||||||
|
def process_file(filename, f):
|
||||||
|
table_name = os.path.basename(filename[:-4] if filename.endswith('.csv') else filename)
|
||||||
|
print(f'-- {table_name} values')
|
||||||
|
for line in f:
|
||||||
|
stripped_line = line.strip()
|
||||||
|
contents = stripped_line.split(',')
|
||||||
|
query_items = []
|
||||||
|
for val in contents:
|
||||||
|
if not is_num(val) and val[0] != "'" and val[-1] != "'":
|
||||||
|
query_items.append(f"'{val}'")
|
||||||
|
else:
|
||||||
|
query_items.append(val)
|
||||||
|
|
||||||
|
value_string = ', '.join(query_items)
|
||||||
|
print(f'INSERT INTO {table_name} VALUES ({value_string});')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
files = glob.glob('data/*.csv')
|
||||||
|
for filename in files:
|
||||||
|
with open(filename) as f:
|
||||||
|
process_file(filename, f)
|
||||||
|
print("")
|
||||||
|
|
Loading…
Reference in New Issue