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.
This commit is contained in:
		| @@ -46,20 +46,24 @@ def fetch_events(): | |||||||
|           else: |           else: | ||||||
|             events.begin = events.begin.to(timezone) |             events.begin = events.begin.to(timezone) | ||||||
|             events.end = events.end.to(timezone) |             events.end = events.end.to(timezone) | ||||||
|           rule = re.search('RRULE:(.+?)\n', event_str).group(0)[:-2] |           try: | ||||||
|           if re.search('UNTIL=(.+?);', rule) and not re.search('UNTIL=(.+?)Z;', rule): |             rule = re.search('RRULE:(.+?)\n', event_str).group(0)[:-2] | ||||||
|             rule = re.sub('UNTIL=(.+?);', 'UNTIL='+re.search('UNTIL=(.+?);', rule).group(0)[6:-1]+'T000000Z;', rule) |             if re.search('UNTIL=(.+?);', rule) and not re.search('UNTIL=(.+?)Z;', rule): | ||||||
|           dates = rrulestr(rule, dtstart= events.begin.datetime).between(after= now.datetime, before = further_future.datetime) |               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: |             if dates: | ||||||
|             duration = events.duration |               duration = events.duration | ||||||
|             for date in dates: |               for date in dates: | ||||||
|               cc = events.clone() |                 cc = events.clone() | ||||||
|               cc.end = arrow.get(date+duration) |                 cc.end = arrow.get(date+duration) | ||||||
|               cc.begin = arrow.get(date) |                 cc.begin = arrow.get(date) | ||||||
|               upcoming_events.append(cc) |                 upcoming_events.append(cc) | ||||||
|               #print("Added '{}' with new start at {}".format(cc.name, cc.begin.format('DD MMM YY'))) |                 #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""" |   """Sort events according to their beginning date""" | ||||||
|   def sort_dates(event): |   def sort_dates(event): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user