1- import csv ,os ,xlrd
2-
3- file_names = ['User' ,'Country' ,'Movie' ,'Language' ,'Topic' ,'Director' ,'Directs' ]
1+ import csv ,os ,xlrd ,pandas
2+ def sheets_names ():
3+ xl = pandas .ExcelFile (excel )
4+ names = xl .sheet_names
5+ for item in names :
6+ file_names .append (item )
7+ print 'Sheets names were being parsed'
48
59def csv_from_excel ():
6- wb = xlrd .open_workbook ('project-data.xls' )
10+ wb = xlrd .open_workbook (excel )
711 for item in file_names :
8- print item
912 file_names_str = str (item )
1013 sh = wb .sheet_by_name (file_names_str )
1114 current_csv = open (file_names_str + '.csv' , 'wb' )
@@ -15,8 +18,9 @@ def csv_from_excel():
1518 wr .writerow (sh .row_values (rownum ))
1619
1720 current_csv .close ()
21+ print 'CSV files were created.'
1822
19- def RepresentsInt (s ):
23+ def check_int (s ):
2024 try :
2125 float (s )
2226 return True
@@ -37,15 +41,18 @@ def populate():
3741 for row in reader :
3842 temp = []
3943 for item in row :
40- if RepresentsInt (item ):
44+ if check_int (item ):
4145 temp .append (int (float (item )))
4246 else :
4347 temp .append (str (item ))
4448 output_file .write ( 'INSERT INTO %s \n VALUES (%s);\n ' % (item_name ,listToStringWithoutBrackets (temp )))
45- # print'File %s.sql is populated.' % item_name
49+ print 'File %s.sql is populated.' % item_name
50+
51+ excel = 'data.xls'
52+ file_names = []
4653
54+ sheets_names ()
4755csv_from_excel ()
48- print 'exported data'
4956for item in file_names :
5057 item_name = str (item )
5158 with open (item_name + '.csv' , 'rb' ) as input_file :
@@ -61,3 +68,4 @@ def populate():
6168 populate ()
6269 else :
6370 populate ()
71+ print '********Execution Complete********'
0 commit comments