title: Calendar .ics to CSV in Python
body: <p>The following code was working well until it found an event without the field description (not sure how that happened), is there a way to continue to the next event when errors are found in one event?</p>
  
  <pre><code># ics to csv example
  # dependency: https://pypi.org/project/vobject/
  
  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":
                  # write to csv
                  csv_writer.writerow([component.summary.valueRepr(),component.attendee.valueRepr(),component.dtstart.valueRepr(),component.dtend.valueRepr(),component.description.valueRepr()])
  </code></pre>
  
  <p>This works as intended now. Thank you @stovfl</p>
  
  <pre><code>import vobject
  import csv
  
  with open('calendar2022.csv', mode='w') as csv_out:
  csv_writer = csv.writer(csv_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  csv_writer.writerow(['WHAT', 'FROM', 'TO', 'DESCRIPTION', 'LOCATION'])
  
      # read the data from the file
  data = open("calendar.ics").read()
  
      # iterate through the contents
  for cal in vobject.readComponents(data):
      for component in cal.components():
          if component.name == "VEVENT":
              writerow = []
              for attr in ['summary', 'dtstart', 'dtend', 'description', 'location']:
                  if hasattr(component, attr):
                      writerow.append(getattr(component, attr).valueRepr())
                  else:
                      writerow.append('Undefined!')
  
              print(writerow)
              csv_writer.writerow(writerow)
  </code></pre>