Created
July 10, 2021 16:18
-
-
Save ankita-kumari/c6f3dcac4570ff18a99c9e99dd47da8b to your computer and use it in GitHub Desktop.
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 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