-
Notifications
You must be signed in to change notification settings - Fork 0
/
classkingsdatabasecreator.py
176 lines (146 loc) · 3.79 KB
/
classkingsdatabasecreator.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from lxml import html
import xlsxwriter
# code to get crn, dept, coursenumber, section, coursecredits, and coursetitle into a excel doc
workbook = xlsxwriter.Workbook('CourseCatalogwTeachers.xlsx')
worksheet = workbook.add_worksheet()
with open('coursesSpring2018.txt') as myFile:
data = myFile.read()
classes = html.fromstring(data)
# note that classes that have two different times will have a \xa0 after them
crn = classes.xpath('//table[@class="datadisplaytable"]//tr//td[2]//text()')
dept = classes.xpath('//table[@class="datadisplaytable"]//tr//td[3]//text()')
courseNumber = classes.xpath('//table[@class="datadisplaytable"]//tr//td[4]//text()')
section = classes.xpath('//table[@class="datadisplaytable"]//tr//td[5]//text()')
courseCredits = classes.xpath('//table[@class="datadisplaytable"]//tr//td[7]//text()')
courseTitle = classes.xpath('//table[@class="datadisplaytable"]//tr//td[8]//text()')
days = classes.xpath('//table[@class="datadisplaytable"]//tr//td[9]//text()') # Need to sort out classes that have different times
time = classes.xpath('//table[@class="datadisplaytable"]//tr//td[10]//text()') # Need way to sort out classes that have two different times
prof = classes.xpath('//table[@class="datadisplaytable"]//tr//td[20]//text()') # get rid of the (', 'P', ')
profNew = []
col = 0
index = 0
row = 0
for item in crn:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, crn[index])
row += 1
index += 1
row = 0
col += 1
index = 0
for item in dept:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, dept[index])
row += 1
index += 1
row = 0
col += 1
index = 0
for item in courseNumber:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, courseNumber[index])
row += 1
index += 1
row = 0
col += 1
index = 0
for item in section:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, section[index])
row += 1
index += 1
row = 0
col += 1
index = 0
for item in courseCredits:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, courseCredits[index])
row += 1
index += 1
row = 0
col += 1
index = 0
for item in courseTitle:
if crn[index] == " ":
index += 1
continue
else:
worksheet.write(row, col, courseTitle[index])
row += 1
index += 1
row = 0
col += 1
index = 0
reference = 0
prof[:] = [x for x in prof if x != 'P']
prof[:] = [x for x in prof if x != ')']
for item in prof:
#Need to add 3rd reference variable to make the list compatible with crn[reference]
if crn[reference] == ' ':
reference += 1
index += 1
continue
elif '),' in prof[index]:
index += 1
continue
else:
profNew.append(prof[index].replace("(", ""))
print(prof[index])
worksheet.write(row, col, profNew[row])
row += 1
index += 1
reference += 1
row = 0
col += 1
index = 0
shift = 0
for item in days:
if crn[index] == " ":
row -= 1
shift += 2
worksheet.write(row, col + shift, days[index])
row += 1
index += 1
continue
else:
worksheet.write(row,col, days[index])
row += 1
index += 1
shift = 0
row = 0
col += 1
index = 0
for item in time:
if crn[index] == " ":
row -= 1
shift += 2
worksheet.write(row, col + shift, time[index])
row += 1
index += 1
continue
else:
worksheet.write(row, col, time[index])
row += 1
index += 1
shift = 0
row = 0
col += 1
index = 0
col += 1
index = 0
workbook.close()