All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 from icalendar import Calendar, Event
6 from textwrap import fill, indent
8 FIELDS = ('summary','location','organiser',
12 COLUMNS = int(os.getenv('COLUMNS', 80))-10
13 WIDTH = max(len(i) for i in FIELDS)
14 INDENT = WIDTH + len(COLSEP)
17 start, end = event.get('dtstart').dt, event.get('dtend')
19 duration = event.get('duration').dt
20 end = start + duration
24 def strftime(dt, strf):
25 return dt.astimezone().strftime(strf)
30 if start.tzinfo == end.tzinfo:
31 ret.append(strftime(start, '%F %R'))
34 ret.append(strftime(start, '%F %R %Z'))
36 if start.date() == end.date():
37 ret.append(strftime(end, '%T %Z'))
40 ret.append(strftime(end, '%F %R %Z'))
44 except AttributeError:
45 return map(lambda d: d.strftime('%F'), (start, end))
47 def parse_ics_file(fp):
48 cal = Calendar.from_ical(fp.read())
50 for event in cal.walk():
51 if event.name != "VEVENT": continue
52 print('{} → {}'.format(*dtstrs(event)))
54 for k in ('status', 'class', 'transp', 'priority'):
56 if t: flags.append((k, t))
57 event['flags'] = ' '.join('{}:{}'.format(*f) for f in flags)
60 text = fill(str(event[label]), width=COLUMNS-INDENT,
61 initial_indent='', subsequent_indent=' '*INDENT)
62 print(f'{label.capitalize():>{WIDTH}s}{COLSEP}{text}')
64 if 'description' in event:
66 lines = event['description'].split('\n')
68 output.append(fill(line, width=COLUMNS, initial_indent=' ',
69 subsequent_indent=' '))
70 print('\n'.join(output))
72 if __name__ == '__main__':
74 if len(sys.argv) > 1 and sys.argv[1] != '-':
75 for f in sys.argv[1:]:
79 parse_ics_file(sys.stdin)