X-Git-Url: https://git.madduck.net/etc/mutt.git/blobdiff_plain/a6ecb48b548b46453f345a296e8d63998a4e1c4f..a83d50d5a64488deb3796bbd0ca0a03b0516cc77:/.mutt/icalparser?ds=sidebyside diff --git a/.mutt/icalparser b/.mutt/icalparser index 38e2fe7..50ed472 100755 --- a/.mutt/icalparser +++ b/.mutt/icalparser @@ -13,8 +13,13 @@ COLUMNS = int(os.getenv('COLUMNS', 80))-10 WIDTH = max(len(i) for i in FIELDS) INDENT = WIDTH + len(COLSEP) -def dtstrs(start, end): - start, end = start.dt, end.dt +def dtstrs(event): + start, end = event.get('dtstart').dt, event.get('dtend') + if not end: + duration = event.get('duration').dt + end = start + duration + else: + end = end.dt def strftime(dt, strf): return dt.astimezone().strftime(strf) @@ -39,7 +44,7 @@ def parse_ics_file(fp): for event in cal.walk(): if event.name != "VEVENT": continue - print('{} → {}'.format(*dtstrs(event.get('dtstart'), event.get('dtend')))) + print('{} → {}'.format(*dtstrs(event))) flags = [] for k in ('status', 'class', 'transp', 'priority'): t = event.get(k) @@ -47,7 +52,7 @@ def parse_ics_file(fp): event['flags'] = ' '.join('{}:{}'.format(*f) for f in flags) for label in FIELDS: if label in event: - text = fill(event[label], width=COLUMNS-INDENT, + text = fill(str(event[label]), width=COLUMNS-INDENT, initial_indent='', subsequent_indent=' '*INDENT) print(f'{label.capitalize():>{WIDTH}s}{COLSEP}{text}')