/
read_curriculum.py
79 lines (53 loc) · 2.6 KB
/
read_curriculum.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from __future__ import print_function
from os.path import join, dirname, abspath
import xlrd
from xlrd.sheet import ctype_text
def read_curriculum():
cname = join(dirname(dirname(abspath(__file__))), 'crs', 'EE-curriculum-October2014 (11).xls')
cl_workbook = xlrd.open_workbook(cname)
sheet_names = cl_workbook.sheet_names()
# print ('Sheet Names', sheet_names)
# print ('hello')
cl_sheet = cl_workbook.sheet_by_name(sheet_names[0])
row = cl_sheet.row(0)
for idx, cell_obj in enumerate(row):
cell_type_str = ctype_text.get(cell_obj.ctype, 'unknown type')
# print ('(%s) %s %s ' % (idx, cell_type_str, cell_obj.value))
num_cols = cl_sheet.ncols
list_of_courses = []
for row_idx in range(1, cl_sheet.nrows):
# print ('-'*40)
# print ('Row: %s ' % row_idx) #print row number
for col_idx in range(0, num_cols): # Iterate through columns
cell_obj = cl_sheet.cell(row_idx, col_idx) # Get cell object by row, col
# print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj))
for row_idx in range(7, 14):
#print ('-'*40)
#print ('Row: %s ' % row_idx) #print row number
list_of_courses.append(cl_sheet.cell(row_idx,0).value)
list_of_courses.append(cl_sheet.cell(row_idx,7).value)
#print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj))
# print (list_of_courses)
for row_idx in range(19, 25):
#print ('-'*40)
#print ('Row: %s ' % row_idx) #print row number
list_of_courses.append(cl_sheet.cell(row_idx,0).value)
list_of_courses.append(cl_sheet.cell(row_idx,7).value)
#print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj))
# print (list_of_courses)
for row_idx in range(30, 36):
#print ('-'*40)
#print ('Row: %s ' % row_idx) #print row number
list_of_courses.append(cl_sheet.cell(row_idx,0).value)
list_of_courses.append(cl_sheet.cell(row_idx,7).value)
#print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj))
# print (list_of_courses)
for row_idx in range(41, 46):
#print ('-'*40)
#print ('Row: %s ' % row_idx) #print row number
list_of_courses.append(cl_sheet.cell(row_idx,0).value)
list_of_courses.append(cl_sheet.cell(row_idx,7).value)
#print ('Column: [%s] cell_obj: [%s]' % (col_idx, cell_obj))
list_of_courses.append(cl_sheet.cell(15,7).value)
# print (list_of_courses)
return list_of_courses