Skip to content

Instantly share code, notes, and snippets.

@inversion
Created October 28, 2012 22:48
Show Gist options
  • Save inversion/3970266 to your computer and use it in GitHub Desktop.
Save inversion/3970266 to your computer and use it in GitHub Desktop.
Export dates from ical file (Python)
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