Skip to content
Snippets Groups Projects
planconvert.py 1.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • import gspread
    
    wonko's avatar
    wonko committed
    import json
    
    from oauth2client.service_account import ServiceAccountCredentials
    
    scope = ['https://spreadsheets.google.com/feeds']
    
    credentials = ServiceAccountCredentials.from_json_keyfile_name('gsheets.json', scope)
    
    
    gc = gspread.authorize(credentials)
    
    ws = gc.open("vortragsplan-beta").sheet1
    
    
    wonko's avatar
    wonko committed
    
    
    wonko's avatar
    wonko committed
    print(ws.updated)
    
    wonko's avatar
    wonko committed
    
    rooms = []
    times = []
    
    data = []
    
    
    def cval(cell):
        cv = cell.value
        if cv:
            cv = cv.strip()
        return cv
    
    
    for cell in ws.range(1,1,1,20):
        room = cval(cell)
        if room:
            room = room.strip()
    
    wonko's avatar
    wonko committed
            if room:
    
                rooms.append(cell)
    
    wonko's avatar
    wonko committed
    
    
    for cell in ws.range(1,1,200,1):
        time = cval(cell)
        if time:
            times.append(cell)
    
    wonko's avatar
    wonko committed
    
    
    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
    
    wonko's avatar
    wonko committed
            row = time.row
    
            fs = cval(ws.cell(row=row, col=col))
    
    wonko's avatar
    wonko committed
            if fs:
                lecture['fs'] = fs
    
            titel = cval(ws.cell(row=row + 1, col=col))
    
    wonko's avatar
    wonko committed
            if titel:
                lecture['titel'] = titel
    
            name = cval(ws.cell(row=row + 2, col=col))
    
    wonko's avatar
    wonko committed
            if name:
                lecture['name'] = name
    
            teaser = cval(ws.cell(row=row + 3, col=col))
    
    wonko's avatar
    wonko committed
            if teaser:
                lecture['teaser'] = teaser
    
            aufz = cval(ws.cell(row=row + 3, col=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)
    
    wonko's avatar
    wonko committed
    jsondata = {'schedule':data, 'version': ws.updated}
    
    wonko's avatar
    wonko committed
    with open('../src/src/assets/data/lectures.json', 'w') as outfile:
    
    wonko's avatar
    wonko committed
        json.dump(jsondata, outfile, indent=1)