]> git.madduck.net Git - etc/mutt.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

prettify icalparser output
authormartin f. krafft <madduck@madduck.net>
Tue, 3 Sep 2019 22:22:50 +0000 (10:22 +1200)
committermartin f. krafft <madduck@madduck.net>
Tue, 3 Sep 2019 22:22:50 +0000 (10:22 +1200)
.mutt/icalparser

index b7a28c96589ea14fc910347878cf31e4eafc4632..38e2fe7c9fbd8472558a73cbaf8ce996d2f6d25d 100755 (executable)
@@ -3,6 +3,15 @@
 import sys
 import os
 from icalendar import Calendar, Event
+from textwrap import fill, indent
+
+FIELDS = ('summary','location','organiser',
+          'flags','uid','rrule')
+COLSEP = ': '
+
+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
@@ -30,22 +39,31 @@ def parse_ics_file(fp):
 
     for event in cal.walk():
         if event.name != "VEVENT": continue
-        print('=' * (int(os.getenv('COLUMNS', 80))-10))
         print('{} → {}'.format(*dtstrs(event.get('dtstart'), event.get('dtend'))))
-        for i in ('summary','organizer','location','uid','rrule'):
-            print('  {:9s}: {}'.format(i.capitalize(), event.get(i, f'(no {i})')))
         flags = []
         for k in ('status', 'class', 'transp', 'priority'):
             t = event.get(k)
             if t: flags.append((k, t))
-        print('  Flags    : ' + ' '.join('{}:{}'.format(*f) for f in flags))
+        event['flags'] = ' '.join('{}:{}'.format(*f) for f in flags)
+        for label in FIELDS:
+            if label in event:
+                text = fill(event[label], width=COLUMNS-INDENT,
+                            initial_indent='', subsequent_indent=' '*INDENT)
+                print(f'{label.capitalize():>{WIDTH}s}{COLSEP}{text}')
+
+        if 'description' in event:
+            output = ['']
+            lines = event['description'].split('\n')
+            for line in lines:
+                output.append(fill(line, width=COLUMNS, initial_indent=' ',
+                                   subsequent_indent=' '))
+            print('\n'.join(output))
 
 if __name__ == '__main__':
 
-    if len(sys.argv) > 1:
+    if len(sys.argv) > 1 and sys.argv[1] != '-':
         for f in sys.argv[1:]:
-            fp = open(f)
-            parse_ics_file(fp)
-            fp.close()
+            with open(f) as fp:
+                parse_ics_file(fp)
     else:
         parse_ics_file(sys.stdin)