Created
October 28, 2012 22:48
-
-
Save inversion/3970266 to your computer and use it in GitHub Desktop.
Export dates from ical file (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from icalendar import Calendar, Event | |
fp = open('basic.ics', 'r') | |
icalStr = "".join(line for line in fp) | |
fp.close() | |
cal = Calendar.from_ical(icalStr) | |
dates = [] | |
# Add start datetimes of events to list for sorting | |
for c in cal.walk('VEVENT'): | |
dates.append(c.decoded('DTSTART')) | |
# Print out dates in ISO 8601 format (earliest first) | |
for d in sorted(dates): | |
print d.strftime('%Y-%m-%d') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment