Skip to content

Commit

Permalink
handle malformed events from ics calendars (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Jun 12, 2023
1 parent 386e672 commit 155b2b0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions events/importer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from datetime import timedelta
from icalendar import Calendar as ICalendar
import requests
Expand All @@ -8,6 +10,8 @@
DATE_RESOLUTION = timedelta(1)
TIME_RESOLUTION = timedelta(0, 0, 1)

logger = logging.getLogger(__name__)


class ICSImporter:
def __init__(self, calendar):
Expand Down Expand Up @@ -37,7 +41,7 @@ def import_occurrence(self, event, event_data):
def import_event(self, event_data):
uid = event_data['UID']
title = event_data['SUMMARY']
description = event_data['DESCRIPTION']
description = event_data.get('DESCRIPTION', '')
location, _ = EventLocation.objects.get_or_create(
calendar=self.calendar,
name=event_data['LOCATION']
Expand Down Expand Up @@ -69,4 +73,7 @@ def get_events(self, ical):
def import_events_from_text(self, ical):
events = self.get_events(ical)
for event in events:
self.import_event(event)
try:
self.import_event(event)
except Exception as exc:
logger.exception(event)

0 comments on commit 155b2b0

Please sign in to comment.