{"id":635,"date":"2015-09-30T15:29:20","date_gmt":"2015-09-30T14:29:20","guid":{"rendered":"https:\/\/hoover.gplrank.de\/?p=635"},"modified":"2015-09-30T19:51:31","modified_gmt":"2015-09-30T18:51:31","slug":"yet-another-python-based-vcalendar-parser","status":"publish","type":"post","link":"https:\/\/hoover.gplrank.de\/?p=635","title":{"rendered":"Yet another Python-based vcalendar parser you can use with &#8220;Mutt&#8221;"},"content":{"rendered":"<div style=\"width: 526px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/symlink.dk\/linux\/config\/mutt\/mutt.png\" alt=\"\" width=\"516\" height=\"269\" \/><p class=\"wp-caption-text\">The Mutt email client at work&#8230; thanks to symlink.dk<\/p><\/div>\n<p>I&#8217;m still using &#8220;<a href=\"http:\/\/www.mutt.org\/\">Mutt<\/a>&#8221; as my main email client if you can believe it, and yes, I know it&#8217;s 2015. Still for me personally nothing allows me to work through my daily inbox at work (which can easily grow to 1,000 new messages a day) quicker than a keyboard-controlled, ASCII only email client like the venerable mutt (before that, I migrated from Unix&#8217; old &#8220;mail&#8221; to &#8220;elm&#8221; in case you remember those).<\/p>\n<p>No matter what tool I tried when attpempting to teach Mutt to show event invitations, parsing exchange-generated vcalendar events never worked properly for me, so I decided to come up with my own (much like every Python hacker worth his salt has to come up with an entire scratch built CMS framework at some point ;))<\/p>\n<p>You can find the results below &#8212; as usual, the code is butt ugly (for some reason, my Python has started looking even worse than my Perl recently if such a thing is possible), but it does the job and works for me; YMMV. \u00a0You&#8217;ll certainly need to translate the field labels into your own language, but that shouldn&#8217;t be too difficult. You can then use mutt&#8217;s &#8220;auto_display&#8221; function to call the script automatically on <em>text\/calendar<\/em> entries.<\/p>\n<p>&nbsp;<\/p>\n<pre>#!\/usr\/bin\/env python\r\nimport sys\r\n\r\nfrom datetime import *\r\n\r\n\r\ndef date_to_string(d):\r\n # 20151006T103000\r\n now=datetime.now()\r\n dt = datetime.strptime(d, \"%Y%m%dT%H%M%S\")\r\n return \"%s (%d days)\" % (dt.strftime(\"%A, %d. %B %Y, %H:%M Uhr\"),\r\n abs (dt-now).days)\r\n\r\n \r\n\r\nif __name__==\"__main__\":\r\n attendees=[]\r\n data=open(sys.argv[1]).readlines()\r\n for l in data:\r\n if l.find(\"ATTENDEE\") &gt; -1:\r\n attendees.append(l.strip().split(\";\")[4].replace('CN=\"', '').split(\",\")[0])\r\n if l.find('DTSTART;')==0:\r\n event_start=l.strip().split(\":\")[1]\r\n if l.find('DTEND;')==0:\r\n event_end=l.strip().split(\":\")[1]\r\n if l.find('SUMMARY;')==0:\r\n event_subject=l.strip().split(\":\")[1]\r\n if l.find('ORGANIZER;')==0:\r\n organizer = l.strip().split(\";\")[1].replace('\"', '')\r\n orga_name, bla, orga_mail = organizer.split(\":\")\r\n orga_name=orga_name.replace('CN=', '')\r\n if l.find(\"LOCATION;\")==0:\r\n location=l.strip().split(\":\")[1].replace('\\\\', '')\r\n\r\n if l.find(\"TZID:\")==0:\r\n time_zone=l.strip().split(\":\")[1]\r\n \r\n \r\n print \"====================================================================\"\r\n print \"Thema : \", event_subject\r\n print \"Ersteller : \", orga_name\r\n print \" \", orga_mail\r\n print \"Start : \", date_to_string(event_start)\r\n print \"Ende : \", date_to_string(event_end)\r\n print \"Zeitzone : \", time_zone\r\n print \"Ort : \", location\r\n print \"Teilnehmer: \", \", \".join(attendees) \r\n print \"====================================================================\"\r\n \r\n sys.exit(0)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m still using &#8220;Mutt&#8221; as my main email client if you can believe it, and yes, I know it&#8217;s 2015. Still for me personally nothing allows me to work through my daily inbox at work (which can easily grow to 1,000 new messages a day) quicker than a keyboard-controlled, ASCII only email client like the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-635","post","type-post","status-publish","format-standard","hentry","category-it"],"_links":{"self":[{"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/posts\/635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=635"}],"version-history":[{"count":4,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":639,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions\/639"}],"wp:attachment":[{"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoover.gplrank.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}