From 7651feb7df1a3c7d4718fa7bdd8c624f18ef3bd5 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 14 Dec 2019 19:19:44 +0100 Subject: [PATCH] Added Error handling for recurring events With the added Error handling, the stability of the recurring-events-parsing section has improved as well. This is handy when using non-supported iCalendars. --- modules/inkycal_icalendar.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/inkycal_icalendar.py b/modules/inkycal_icalendar.py index f056fb3..044df27 100644 --- a/modules/inkycal_icalendar.py +++ b/modules/inkycal_icalendar.py @@ -46,20 +46,24 @@ def fetch_events(): else: events.begin = events.begin.to(timezone) events.end = events.end.to(timezone) - rule = re.search('RRULE:(.+?)\n', event_str).group(0)[:-2] - if re.search('UNTIL=(.+?);', rule) and not re.search('UNTIL=(.+?)Z;', rule): - rule = re.sub('UNTIL=(.+?);', 'UNTIL='+re.search('UNTIL=(.+?);', rule).group(0)[6:-1]+'T000000Z;', rule) - dates = rrulestr(rule, dtstart= events.begin.datetime).between(after= now.datetime, before = further_future.datetime) + try: + rule = re.search('RRULE:(.+?)\n', event_str).group(0)[:-2] + if re.search('UNTIL=(.+?);', rule) and not re.search('UNTIL=(.+?)Z;', rule): + rule = re.sub('UNTIL=(.+?);', 'UNTIL='+re.search('UNTIL=(.+?);', rule).group(0)[6:-1]+'T000000Z;', rule) + dates = rrulestr(rule, dtstart= events.begin.datetime).between(after= now.datetime, before = further_future.datetime) - if dates: - duration = events.duration - for date in dates: - cc = events.clone() - cc.end = arrow.get(date+duration) - cc.begin = arrow.get(date) - upcoming_events.append(cc) - #print("Added '{}' with new start at {}".format(cc.name, cc.begin.format('DD MMM YY'))) + if dates: + duration = events.duration + for date in dates: + cc = events.clone() + cc.end = arrow.get(date+duration) + cc.begin = arrow.get(date) + upcoming_events.append(cc) + #print("Added '{}' with new start at {}".format(cc.name, cc.begin.format('DD MMM YY'))) + except Exception as e: + print('Something went wrong while parsing recurring events') + pass """Sort events according to their beginning date""" def sort_dates(event):