-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
86 lines (78 loc) · 4.9 KB
/
reader.py
File metadata and controls
86 lines (78 loc) · 4.9 KB
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
from xlrd import open_workbook
import client
# xl_workbook = open_work9book("teaching_timetable.xls")
xl_workbook = open_workbook("AUGUST_SEMESTER_2016.xls", formatting_info=True)
def get_days(sheet):
temp = {}
for col in range(sheet.ncols):
value = sheet.cell(1, col).value
if value:
if value not in temp:
temp[value] = []
temp[value].append(col)
return temp
def parse_timetable():
client.authenticate()
for sheet in xl_workbook.sheets():
sheet_name = sheet.name
days_row_index = get_days(sheet)
if "Athi" in sheet_name:
client.create_collection("athitt")
print("\n" + sheet_name)
if sheet.ncols < 14:
for row in [x for x in range(3, sheet.nrows)]:
for col in [x for x in range(1, sheet.ncols) if (x != 3) and (x != 8)]:
if sheet.cell(row, col).value:
for k in days_row_index.keys():
if col in days_row_index[k]:
time = sheet.cell(2, col).value.split('-')
body = dict(location=sheet.cell(row, 0).value, start_time=time[0],
end_tiem=time[1], day=sheet.cell(1, col).value)
title = sheet.cell(row, col).value
data = dict(title="".join(title.split()), body=body)
client.create_document("athitt", data)
# print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value+" : "+sheet.cell(row, 0).value+" : "+sheet.cell(2, col).value)
else:
for row in [x for x in range(3, sheet.nrows)]:
for col in [x for x in range(1, sheet.ncols) if (x != 3) and (x != 8) and (x != 9)]:
if sheet.cell(row, col).value:
for k in days_row_index.keys():
if col in days_row_index[k]:
time = sheet.cell(2, col).value.split('-')
body = dict(location=sheet.cell(row, 0).value, start_time=time[0],
end_tiem=time[1], day=sheet.cell(1, col).value)
title = sheet.cell(row, col).value
data = dict(title="".join(title.split()), body=body)
client.create_document("athitt", data)
# print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value + " : " + sheet.cell(row, 0).value + " : " + sheet.cell(2,col).value)
elif "Day" in sheet_name:
client.create_collection("nairobidaytt")
print("\n" + sheet_name)
for row in [x for x in range(3, sheet.nrows)]:
for col in [x for x in range(1, sheet.ncols) if (x != 5) and (x != 9) and (x != 11)]:
if sheet.cell(row, col).value:
for k in days_row_index.keys():
if col in days_row_index[k]:
time = sheet.cell(2, col).value.split('-')
body = dict(location=sheet.cell(row, 0).value, start_time=time[0],
end_tiem=time[1], day=sheet.cell(1, col).value)
title = sheet.cell(row, col).value
data = dict(title="".join(title.split()), body=body)
client.create_document("nairobidaytt", data)
# print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value+" : "+sheet.cell(row, 0).value+" : "+sheet.cell(2, col).value)
elif "Evening" in sheet_name:
client.create_collection("nairobieveningtt")
print("\n" + sheet_name)
for row in [x for x in range(3, sheet.nrows)]:
for col in [x for x in range(1, sheet.ncols) if (x != 5)]:
if sheet.cell(row, col).value:
for k in days_row_index.keys():
if col in days_row_index[k]:
time = sheet.cell(2, col).value.split('-')
body = dict(location=sheet.cell(row, 0).value, start_time=time[0],
end_tiem=time[1], day=sheet.cell(1, col).value)
title = sheet.cell(row, col).value
data = dict(title="".join(title.split()), body=body)
client.create_document("nairobieveningtt", data)
# print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value+" : "+sheet.cell(row, 0).value+" : "+sheet.cell(2, col).value)
parse_timetable()