4
4
import sys
5
5
import re
6
6
7
- #This will hold the table name as key, and columns as values.
7
+ # This will hold the table name as key, and columns as values.
8
8
mainDict = {}
9
9
10
10
11
11
def createStatement (line ):
12
12
return line .startswith ('CREATE TABLE' )
13
13
14
- #to detect fields, aka column names
14
+ # To detect fields, aka column names
15
15
def fieldDef (line ):
16
16
return line .strip ().startswith ('`' )
17
17
@@ -31,15 +31,15 @@ def getCleanedValue(line):
31
31
32
32
def getValueTuple (line ):
33
33
values = line .partition (' VALUES ' )[- 1 ].strip ().replace ('NULL' , "''" )
34
- #To exclude the ;
34
+ # To exclude the ;
35
35
if values [- 1 ] == ';' :
36
36
values = values [:- 1 ]
37
37
38
38
return ast .literal_eval (values )
39
39
40
40
41
41
def writeFile (outputDirectory , tableName , schema , values ):
42
- #File name that the current table will be assigned to
42
+ # File name that the current table will be assigned to
43
43
fileName = os .path .join (outputDirectory , '%s.csv' % (tableName ,))
44
44
with open (fileName , 'w' ) as writeFile :
45
45
writer = csv .DictWriter (writeFile , fieldnames = schema )
@@ -65,5 +65,6 @@ def parseFile(fileName, outputDirectory):
65
65
values = getValueTuple (line )
66
66
writeFile (outputDirectory , tableName , currentTable , values )
67
67
68
+
68
69
if __name__ == '__main__' :
69
70
parseFile (sys .argv [1 ], sys .argv [2 ])
0 commit comments