Skip to content

Instantly share code, notes, and snippets.

@ankita-kumari
Created July 10, 2021 16:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankita-kumari/c6f3dcac4570ff18a99c9e99dd47da8b to your computer and use it in GitHub Desktop.
Save ankita-kumari/c6f3dcac4570ff18a99c9e99dd47da8b to your computer and use it in GitHub Desktop.
import vobject
import csv
with open('sample.csv', mode='w') as csv_out:
csv_writer = csv.writer(csv_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(['WHAT', 'WHO', 'FROM', 'TO', 'DESCRIPTION'])
# read the data from the file
data = open("sample.ics").read()
# iterate through the contents
for cal in vobject.readComponents(data):
for component in cal.components():
if component.name == "VEVENT":
isaccepted = False
isaccepted = 'attendee' in component.contents and len(component.contents['attendee']) > 0 and component.contents['attendee'][0].params['PARTSTAT'][0] == 'ACCEPTED'
if isaccepted:
writerow = []
for attr in ['summary', 'attendee', 'dtstart', 'dtend', 'description']:
if hasattr(component, attr):
writerow.append(getattr(component, attr).valueRepr())
else:
writerow.append('Undefined!')
print(writerow)
csv_writer.writerow(writerow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment