forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcalparse
executable file
·37 lines (29 loc) · 1.2 KB
/
vcalparse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# Simple demo of how to use vobject to parse an icalendar file with vobject.
# vobject doesn't have much documentation, so this was puzzled out
# mostly by trial and error.
# To use this in mutt, add a mailcap entry like this:
# text/calendar; /home/akkana/bin/vcalparse %s; copiousoutput
# Sadly, auto_view doesn't work for these in mutt. I don't know why not.
import sys
import vobject
TIME_FMT = "%Y-%m-%d %H:%M"
def parse_vcal_file(f):
with open(f) as fp:
parsedCal = vobject.readOne(fp)
print("*** EVENT ***")
print("Summary:", parsedCal.vevent.summary.value)
print("Organizer:", parsedCal.vevent.organizer.value)
print("Start:", parsedCal.vevent.dtstart.value.strftime(TIME_FMT))
print("End: ", parsedCal.vevent.dtend.value.strftime(TIME_FMT))
# There are attendees, but there doesn't seem to be any way
# to loop over them; you can get one of them with
# parsedCal.vevent.attendee but how do you get the rest?
print("Attending:")
for att in parsedCal.vevent.contents["attendee"]:
print(" ", att.value)
print(parsedCal.vevent.dtstart)
print()
if __name__ == "__main__":
for f in sys.argv[1:]:
parse_vcal_file(f)