Newer
Older
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
from openpyxl import load_workbook
import json
wb = load_workbook(filename = 'vortragsplan-13.5..xlsx')
ws = wb['Tabelle1']
rooms = []
times = []
data = []
def cval(cell):
cv = cell.value
if cv:
cv = cv.strip()
return cv
for rows in ws.iter_cols(min_col=2,min_row=1,max_row=1):
for cell in rows:
room = cval(cell)
if room:
room = room.strip()
if room:
rooms.append(cell)
for rows in ws.iter_rows(min_col=1,min_row=1,max_row=ws.max_row+1,max_col=1):
for cell in rows:
time = cval(cell)
if time:
times.append(cell)
for room in rooms:
roomdata = {'name':room.value}
timeslots = []
for time in times:
timeslot = {'time': time.value}
lecture = {}
col = room.col_idx
row = time.row
fs = cval(ws.cell(row=row, column=col))
if fs:
lecture['fs'] = fs
name = cval(ws.cell(row=row+1, column=col))
if name:
lecture['name'] = name
titel = cval(ws.cell(row=row+2, column=col))
if titel:
lecture['titel'] = titel
aufz = cval(ws.cell(row=row+3, column=col))
if aufz:
lecture['aufz'] = aufz
if len(lecture) > 0:
lecture['time'] = time.value
lecture['room'] = room.value
timeslot['lecture'] = lecture
timeslots.append(timeslot)
roomdata['times'] = timeslots
data.append(roomdata)
print (data)
jsondata = {'schedule':data}
with open('../src/www/data/lectures.json', 'w') as outfile:
json.dump(jsondata, outfile, indent=1)