Skip to content

Commit ee9c01d

Browse files
committed
Yeah
1 parent 8a7cdf7 commit ee9c01d

6 files changed

Lines changed: 55 additions & 15 deletions

File tree

Company.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"CompanyID","companyname","companyIndustry"
2+
"C001","SDFESDF","IT"
3+
"C002","DAWR","Electronics"
4+
"C003","SDFD","IT"
5+
"C004","F","IT"
6+
"C005","DFEF","IT"

Company.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO Company
2+
VALUES ('C001', 'SDFESDF', 'IT');
3+
INSERT INTO Company
4+
VALUES ('C002', 'DAWR', 'Electronics');
5+
INSERT INTO Company
6+
VALUES ('C003', 'SDFD', 'IT');
7+
INSERT INTO Company
8+
VALUES ('C004', 'F', 'IT');
9+
INSERT INTO Company
10+
VALUES ('C005', 'DFEF', 'IT');

InsertGenerator.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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

59
def 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 \nVALUES (%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()
4755
csv_from_excel()
48-
print 'exported data'
4956
for 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********'

User.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"UserID","username","hashedpassword","BirthYear"
2+
"U001","A","EDD3382A8DC3EEC1128E0F1204FFC24A","1990.0"
3+
"U002","ABS","CEEE82D7C69FC782A8ABDA645E4B8AA2","1993.0"
4+
"U003","ABSD","AEAF1F6726389BC3CDCC264FAD846A0D","1999.0"
5+
"U004","ASBDF","F7AD1B3A0F27E557FC2D8A37E7B837EC","1989.0"
6+
"U005","SDFEK","C17410EDFD7DE00B371F245134DD53D6","1992.0"

User.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO User
2+
VALUES ('U001', 'A', 'EDD3382A8DC3EEC1128E0F1204FFC24A', 1990);
3+
INSERT INTO User
4+
VALUES ('U002', 'ABS', 'CEEE82D7C69FC782A8ABDA645E4B8AA2', 1993);
5+
INSERT INTO User
6+
VALUES ('U003', 'ABSD', 'AEAF1F6726389BC3CDCC264FAD846A0D', 1999);
7+
INSERT INTO User
8+
VALUES ('U004', 'ASBDF', 'F7AD1B3A0F27E557FC2D8A37E7B837EC', 1989);
9+
INSERT INTO User
10+
VALUES ('U005', 'SDFEK', 'C17410EDFD7DE00B371F245134DD53D6', 1992);

test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import pandas as pd
2-
xl = pd.ExcelFile('data.xls')
1+
import pandas
2+
xl = pandas.ExcelFile('data.xls')
33

4-
xl.sheet_names # see all sheet names
5-
6-
xl.parse(sheet_name)
7-
print sheet_name
4+
names = xl.sheet_names # see all sheet names
5+
file_names = []
6+
for item in names:
7+
file_names.append(item)

0 commit comments

Comments
 (0)