Skip to content
Snippets Groups Projects
Commit 18b6ebb2 authored by wonko's avatar wonko
Browse files

vortraege aus google sheet direct in json

parent 09dddcbc
No related branches found
No related tags found
No related merge requests found
from openpyxl import load_workbook import gspread
import json import json
wb = load_workbook(filename='vortragsplan-17.5..xlsx') from oauth2client.service_account import ServiceAccountCredentials
ws = wb['Tabelle1']
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
rooms = [] rooms = []
...@@ -16,19 +25,17 @@ def cval(cell): ...@@ -16,19 +25,17 @@ def cval(cell):
cv = cv.strip() cv = cv.strip()
return cv return cv
for rows in ws.iter_cols(min_col=2, min_row=1, max_row=1): for cell in ws.range(1,1,1,20):
for cell in rows: room = cval(cell)
room = cval(cell) if room:
room = room.strip()
if room: if room:
room = room.strip() rooms.append(cell)
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 ws.range(1,1,200,1):
for cell in rows: time = cval(cell)
time = cval(cell) if time:
if time: times.append(cell)
times.append(cell)
for room in rooms: for room in rooms:
...@@ -40,21 +47,21 @@ for room in rooms: ...@@ -40,21 +47,21 @@ for room in rooms:
timeslot = {'time': time.value, 'begin': be[0].strip(), 'end':be[1].strip()} timeslot = {'time': time.value, 'begin': be[0].strip(), 'end':be[1].strip()}
lecture = {} lecture = {}
col = room.col_idx col = room.col
row = time.row row = time.row
fs = cval(ws.cell(row=row, column=col)) fs = cval(ws.cell(row=row, col=col))
if fs: if fs:
lecture['fs'] = fs lecture['fs'] = fs
titel = cval(ws.cell(row=row + 1, column=col)) titel = cval(ws.cell(row=row + 1, col=col))
if titel: if titel:
lecture['titel'] = titel lecture['titel'] = titel
name = cval(ws.cell(row=row + 2, column=col)) name = cval(ws.cell(row=row + 2, col=col))
if name: if name:
lecture['name'] = name lecture['name'] = name
teaser = cval(ws.cell(row=row + 3, column=col)) teaser = cval(ws.cell(row=row + 3, col=col))
if teaser: if teaser:
lecture['teaser'] = teaser lecture['teaser'] = teaser
aufz = cval(ws.cell(row=row + 3, column=col)) aufz = cval(ws.cell(row=row + 3, col=col))
if aufz: if aufz:
lecture['aufz'] = aufz lecture['aufz'] = aufz
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment