]> 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:

add icalparser
authormartin f. krafft <madduck@madduck.net>
Wed, 15 Aug 2018 00:06:28 +0000 (12:06 +1200)
committermartin f. krafft <madduck@madduck.net>
Wed, 15 Aug 2018 00:07:35 +0000 (12:07 +1200)
.gitignore.d/mutt
.mutt/icalparser [new file with mode: 0755]

index ce028e0a412ccba7ccfc2535c6b08a2323267cf1..bfea42ac76a9c2394baf1d627cea37cd725c4961 100644 (file)
@@ -15,6 +15,7 @@
 !/.mutt/.gitignore
 !/.mutt/headers
 !/.mutt/hooks
 !/.mutt/.gitignore
 !/.mutt/headers
 !/.mutt/hooks
+!/.mutt/icalparser
 !/.mutt/keybindings
 !/.mutt/list-mailboxes
 !/.mutt/lists
 !/.mutt/keybindings
 !/.mutt/list-mailboxes
 !/.mutt/lists
diff --git a/.mutt/icalparser b/.mutt/icalparser
new file mode 100755 (executable)
index 0000000..b2b1af3
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/python3
+
+import sys
+import os
+from icalendar import Calendar, Event
+
+def dtstrs(start, end):
+    start, end = start.dt, end.dt
+
+    def strftime(dt, strf):
+        return dt.astimezone().strftime(strf)
+
+    ret = []
+    if start.tzinfo == end.tzinfo:
+        ret.append(strftime(start, '%F %R'))
+
+    else:
+        ret.append(strftime(start, '%F %R %Z'))
+
+    if start.date() == end.date():
+        ret.append(strftime(end, '%T %Z'))
+
+    else:
+        ret.append(strftime(end, '%F %R %Z'))
+
+    return ret
+
+def parse_ics_file(fp):
+    cal = Calendar.from_ical(fp.read())
+
+    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','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))
+
+if __name__ == '__main__':
+
+    if len(sys.argv) > 1:
+        for f in sys.argv[1:]:
+            fp = open(f)
+            parse_ics_file(fp)
+            fp.close()
+    else:
+        parse_ics_file(sys.stdin)