Created
March 24, 2022 00:30
-
-
Save paulegan/c982481b766ea56ea08bf127da09d503 to your computer and use it in GitHub Desktop.
Convert ical file to a csv
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
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