Skip to content

Instantly share code, notes, and snippets.

@paulegan
Created March 24, 2022 00:30
Show Gist options
  • Save paulegan/c982481b766ea56ea08bf127da09d503 to your computer and use it in GitHub Desktop.
Save paulegan/c982481b766ea56ea08bf127da09d503 to your computer and use it in GitHub Desktop.
Convert ical file to a csv
import sys
import csv
import icalendar
with open(sys.argv[1]) as f:
cal = icalendar.Calendar.from_ical(f.read())
with open(sys.argv[2], 'w') as f:
csv.writer(f).writerows(
(
e['dtstart'].dt.isoformat()[:19],
e['dtend'].dt.isoformat()[:19],
(e['dtend'].dt - e['dtstart'].dt).total_seconds() / 3600,
e.get('summary', ''),
e.get('description', ''),
e.get('location', ''),
e.get('status', ''),
str(e.get('organizer', '')).removeprefix('mailto:'),
','.join(str(a).removeprefix('mailto:') for a in e.get('attendee', []))
)
for e in cal.walk() if e.name == 'VEVENT' and e.get('dtend')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment