From 3b25773b592b0251f14d649ed7715b3da802c7ad Mon Sep 17 00:00:00 2001 From: Carlos Hanson Date: Wed, 23 Jan 2019 14:47:45 -0800 Subject: [PATCH 1/2] Fix UnicodeEncodeError: 'ascii' codec can't encode character. See Issue #21. --- icalevents/icalparser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/icalevents/icalparser.py b/icalevents/icalparser.py index e5070e5..6966475 100644 --- a/icalevents/icalparser.py +++ b/icalevents/icalparser.py @@ -140,8 +140,14 @@ def create_event(component, tz=UTC): else: # compute implicit end as start + 0 event.end = event.start - event.summary = str(component.get('summary')) - event.description = str(component.get('description')) + try: + event.summary = str(component.get('summary')) + except UnicodeEncodeError as e: + event.summary = str(component.get('summary').encode('utf-8')) + try: + event.description = str(component.get('description')) + except UnicodeEncodeError as e: + event.description = str(component.get('description').encode('utf-8')) event.all_day = type(component.get('dtstart').dt) is date if component.get('rrule'): event.recurring = True From e26fdc34de34a79e2cab9520108a30cef2038bc2 Mon Sep 17 00:00:00 2001 From: carloshanson Date: Wed, 23 Jan 2019 15:55:23 -0800 Subject: [PATCH 2/2] Add a 'location' attribute to Event. --- icalevents/icalparser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/icalevents/icalparser.py b/icalevents/icalparser.py index 6966475..5b384a4 100644 --- a/icalevents/icalparser.py +++ b/icalevents/icalparser.py @@ -41,6 +41,7 @@ class Event: self.end = None self.all_day = True self.recurring = False + self.location = None def time_left(self, time=now()): """ @@ -115,6 +116,7 @@ class Event: ne.all_day = self.all_day ne.recurring = self.recurring + ne.location = self.location ne.uid = uid return ne @@ -151,6 +153,10 @@ def create_event(component, tz=UTC): event.all_day = type(component.get('dtstart').dt) is date if component.get('rrule'): event.recurring = True + try: + event.location = str(component.get('location')) + except UnicodeEncodeError as e: + event.location = str(component.get('location').encode('utf-8')) return event