Handle error if ical is malformed
This commit is contained in:
parent
0cacd98f23
commit
a359d7ae04
|
@ -4,9 +4,9 @@ from typing import List, Tuple, Optional
|
||||||
import caldav
|
import caldav
|
||||||
from caldav import Calendar, vcal
|
from caldav import Calendar, vcal
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from ics import Event
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
from ics import Event
|
|
||||||
|
|
||||||
|
|
||||||
class CalDAVServer(models.Model):
|
class CalDAVServer(models.Model):
|
||||||
|
@ -75,7 +75,7 @@ class CalDAVCalendar(models.Model):
|
||||||
:return Amount of events added, updated, and deleted
|
:return Amount of events added, updated, and deleted
|
||||||
:rtype Tuple[int, int, int]
|
:rtype Tuple[int, int, int]
|
||||||
"""
|
"""
|
||||||
logger = logging.getLogger("davinci.icalendar.ICalSync.upload_events")
|
logger = logging.getLogger("davinci.icalendar.CalDAVCalendar.upload_events")
|
||||||
calendar = self.get_calendar()
|
calendar = self.get_calendar()
|
||||||
if calendar is None:
|
if calendar is None:
|
||||||
logger.error(f"No calendar found on url '{self.calendar_url}'")
|
logger.error(f"No calendar found on url '{self.calendar_url}'")
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import humanize
|
import humanize
|
||||||
|
@ -29,8 +30,14 @@ class ICalSync(models.Model):
|
||||||
return humanize.precisedelta(self.sync_interval)
|
return humanize.precisedelta(self.sync_interval)
|
||||||
|
|
||||||
def get_events(self):
|
def get_events(self):
|
||||||
|
logger = logging.getLogger("davinci.icalendar.ICalSync.get_events")
|
||||||
data = ical_utils.get_ical_from_url(self.ical_url)
|
data = ical_utils.get_ical_from_url(self.ical_url)
|
||||||
events = ical_utils.split_events(data)
|
try:
|
||||||
|
events = ical_utils.split_events(data)
|
||||||
|
except ValueError as e:
|
||||||
|
logger.error(f"ValueError while parsing events from iCal {self.name}: {e}. Please check iCal (URL: {self.ical_url} ) for correct format.")
|
||||||
|
return []
|
||||||
|
|
||||||
# We have to pad the uids with some string related to the target calendar,
|
# We have to pad the uids with some string related to the target calendar,
|
||||||
# So that if someone wants to sync the same .ics to two calendars, the UIDs are different.
|
# So that if someone wants to sync the same .ics to two calendars, the UIDs are different.
|
||||||
fixed_events = ical_utils.fix_ical_uids(events, self.target)
|
fixed_events = ical_utils.fix_ical_uids(events, self.target)
|
||||||
|
|
Loading…
Reference in a new issue