Skip to content

Instantly share code, notes, and snippets.

@ankita-kumari
Created July 10, 2021 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankita-kumari/583485cf11104f879496c037fb4f73b8 to your computer and use it in GitHub Desktop.
Save ankita-kumari/583485cf11104f879496c037fb4f73b8 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 6.
import vobject
import csv
import sys
# total arguments
n = len(sys.argv)
print("Total arguments passed:", n)
# Arguments passed
print("\nName of Python script:", sys.argv[0])
print("\nArguments passed:", end = " ")
for i in range(1, n):
print(sys.argv[i], end = " ")
email = sys.argv[1]
# Parses cal and writes to CSV
def parsecal(email):
outfile = email.split('@')[0] + ".csv"
infile = email.split('@')[0] + ".ics"
with open(outfile, mode='w') as csv_out:
csv_writer = csv.writer(csv_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(['WHAT', 'WHO', '#ATTENDEES', 'FROM', 'TO', 'DESCRIPTION'])
# read the data from the file
data = open(infile).read()
# iterate through the contents
for cal in vobject.readComponents(data):
for component in cal.components():
if component.name == "VEVENT" and isaccepted(component, email):
writerow = []
for attr in ['summary', 'attendee', 'dtstart', 'dtend', 'description']:
if hasattr(component, attr):
if attr == 'attendee':
attendees = getattendees(component)
writerow.append(','.join(attendees))
writerow.append(len(attendees))
else:
writerow.append(getattr(component, attr).valueRepr())
else:
writerow.append('Undefined!')
if attr == 'attendee':
writerow.append('Undefined!')
print(writerow)
csv_writer.writerow(writerow)
# Get list of participants
def getattendees(event):
attendees = []
if 'attendee' not in component.contents:
return attendees
for attendee in component.contents['attendee']:
attendees.append(attendee.params['CN'])
return attendees
# Checks if person accepted the invite
def isaccepted(event, email):
if 'attendee' not in component.contents:
return False
for attendee in component.contents['attendee']:
if attendee.params['CN'] == email and attendee.params['PARTSTAT'][0] == 'ACCEPTED':
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment