Skip to content
Snippets Groups Projects
planconver.py 1.83 KiB
Newer Older
wonko's avatar
wonko committed
from openpyxl import load_workbook
import json
wonko's avatar
wonko committed
wb = load_workbook(filename='vortragsplan-13.5..xlsx')
wonko's avatar
wonko committed
ws = wb['Tabelle1']


rooms = []
times = []

data = []


def cval(cell):
    cv = cell.value
    if cv:
        cv = cv.strip()
    return cv

wonko's avatar
wonko committed
for rows in ws.iter_cols(min_col=2, min_row=1, max_row=1):
wonko's avatar
wonko committed
    for cell in rows:
        room = cval(cell)
        if room:
            room = room.strip()
            if room:
                rooms.append(cell)

wonko's avatar
wonko committed
for rows in ws.iter_rows(min_col=1, min_row=1, max_row=ws.max_row + 1, max_col=1):
wonko's avatar
wonko committed
    for cell in rows:
        time = cval(cell)
        if time:
            times.append(cell)


for room in rooms:
    roomdata = {'name':room.value}
    timeslots = []
wonko's avatar
wonko committed
    for time in times:
        timename = time.value
        be = timename.split('-')
        timeslot = {'time': time.value, 'begin': be[0].strip(), 'end':be[1].strip()}

wonko's avatar
wonko committed
        lecture = {}
        col = room.col_idx
        row = time.row
        fs = cval(ws.cell(row=row, column=col))
        if fs:
            lecture['fs'] = fs
wonko's avatar
wonko committed
        titel = cval(ws.cell(row=row + 1, column=col))
wonko's avatar
wonko committed
        if titel:
            lecture['titel'] = titel
wonko's avatar
wonko committed
        name = cval(ws.cell(row=row + 2, column=col))
        if name:
            lecture['name'] = name
        teaser = cval(ws.cell(row=row + 3, column=col))
        if teaser:
            lecture['teaser'] = teaser
        aufz = cval(ws.cell(row=row + 3, column=col))
wonko's avatar
wonko committed
        if aufz:
            lecture['aufz'] = aufz
wonko's avatar
wonko committed

wonko's avatar
wonko committed
        if len(lecture) > 0:
            lecture['time'] = time.value
            lecture['room'] = room.value
            timeslot['lecture'] = lecture
        timeslots.append(timeslot)
    roomdata['times'] = timeslots
wonko's avatar
wonko committed
    data.append(roomdata)
wonko's avatar
wonko committed
print (data)
jsondata = {'schedule':data}
with open('../src/www/data/lectures.json', 'w') as outfile:
    json.dump(jsondata, outfile, indent=1)