Skip to content

Commit

Permalink
Merge pull request #44 from tahouse/master
Browse files Browse the repository at this point in the history
added support for default_span adjustment and additional event components
  • Loading branch information
irgangla authored Feb 7, 2019
2 parents ccf7cb4 + fd8c435 commit 08456f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
24 changes: 19 additions & 5 deletions icalevents/icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
from icalendar.prop import vDDDLists


# default query length (one week)
default_span = timedelta(days=7)


def now():
"""
Get current time.
Expand Down Expand Up @@ -158,6 +154,23 @@ def create_event(component, tz=UTC):
event.location = str(component.get('location'))
except UnicodeEncodeError as e:
event.location = str(component.get('location').encode('utf-8'))

if component.get('attendee'):
event.attendee = component.get('attendee')
if type(event.attendee) is list:
temp = []
for a in event.attendee:
temp.append(a.encode('utf-8').decode('ascii'))
event.attendee = temp
else:
event.attendee = event.attendee.encode('utf-8').decode('ascii')

if component.get('uid'):
event.uid = component.get('uid').encode('utf-8').decode('ascii')

if component.get('organizer'):
event.organizer = component.get('organizer').encode('utf-8').decode('ascii')

return event


Expand All @@ -184,13 +197,14 @@ def normalize(dt, tz=UTC):
return dt


def parse_events(content, start=None, end=None):
def parse_events(content, start=None, end=None, default_span=timedelta(days=7)):
"""
Query the events occurring in a given time range.
:param content: iCal URL/file content as String
:param start: start date for search, default today
:param end: end date for search
:param default_span: default query length (one week)
:return: events as list
"""
if not start:
Expand Down
17 changes: 16 additions & 1 deletion test/test_icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ def setUp(self):
self.eventA.end = datetime(year=2017, month=2, day=3, hour=15, minute=5, tzinfo=UTC)
self.eventA.all_day = False
self.eventA.summary = "Event A"
self.eventA.attendee = "[email protected]"
self.eventA.organizer = "[email protected]"


self.eventB = icalevents.icalparser.Event()
self.eventB.uid = 1234
self.eventB.start = datetime(year=2017, month=2, day=1, hour=15, minute=5, tzinfo=UTC)
self.eventB.end = datetime(year=2017, month=2, day=1, hour=16, minute=5, tzinfo=UTC)
self.eventB.all_day = False
self.eventB.summary = "Event B"

self.eventB.attendee = ["[email protected]", "[email protected]"]
self.eventB.organizer = "[email protected]"


self.dtA = datetime(2018, 6, 21, 12)
self.dtB = datetime(2018, 6, 21, 12, tzinfo=gettz('Europe/Berlin'))

Expand Down Expand Up @@ -88,3 +94,12 @@ def test_normalize(self):

with self.assertRaises(ValueError, msg="type check effective"):
icalevents.icalparser.normalize(None)

def test_attendee(self):
self.assertIsInstance(self.eventA.attendee, str)
self.assertIsInstance(self.eventB.attendee, list)

def test_organizer(self):
self.assertIsInstance(self.eventA.organizer, str)
self.assertIsInstance(self.eventB.organizer, str)

0 comments on commit 08456f2

Please sign in to comment.