diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-12-27 13:55:49 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-12-27 13:55:49 +0100 |
commit | 5f84955b0626ca1446f7356025a95e4c574b50f4 (patch) | |
tree | 55152c36f820c7345f3d1b1925ca4d82859fc850 | |
parent | 227be35ad8dc8377ae3afd7a908e3b52932243a1 (diff) |
added toetsrooster2ical script
-rwxr-xr-x | .local/share/bin/toetsrooster2ical | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/.local/share/bin/toetsrooster2ical b/.local/share/bin/toetsrooster2ical new file mode 100755 index 0000000..5de58cb --- /dev/null +++ b/.local/share/bin/toetsrooster2ical @@ -0,0 +1,38 @@ +#!/bin/python3 + +import sys +import xlrd +from datetime import datetime +import json +from icalendar import Calendar, Event +from uuid import uuid4 as uuid +import pytz + +workbook = xlrd.open_workbook(sys.argv[1]) +sheet = workbook.sheet_by_index(0) +cal = Calendar() + +cal.add('prodid', 'toetsrooster2ical') +cal.add('version', '2.0') + +def time_to_tuple(timestr): + return (int(timestr[0:2]), int(timestr[3:5])) + +for toets in range(8, sheet.nrows): + toetsdata = sheet.row_values(toets) + event = Event() + + date = xlrd.xldate_as_tuple(toetsdata[10], workbook.datemode) + times = toetsdata[11].split(" - ") + + event.add('summary', toetsdata[4]) + event.add('dtstart', datetime(*date[0:3], *time_to_tuple(times[0]))) + event.add('dtend', datetime(*date[0:3], *time_to_tuple(times[1]))) + event.add('location', toetsdata[14]) + + cal.add_component(event) + +f = open('out.ics', 'wb') +f.write(cal.to_ical()) +f.close() + |