fixed loading from file

This commit is contained in:
Ace 2020-12-02 00:58:37 +01:00
parent f6de947096
commit 07fd9d9b57

View File

@ -84,14 +84,19 @@ class iCalendar:
example: 'path1' (single file) OR ['path1', 'path2'] (multiple files) example: 'path1' (single file) OR ['path1', 'path2'] (multiple files)
returns a list of iCalendars as string (raw) returns a list of iCalendars as string (raw)
""" """
if type(filepath) == list: if isinstance(filepath, list):
ical = (Calendar.from_ical(open(path)) for path in filepath) for path in filepath:
elif type(filepath) == str: with open(path, mode='r') as ical_file:
ical = (Calendar.from_ical(open(path))) ical = (Calendar.from_ical(ical_file.read()))
self.icalendars += ical
elif isinstance(filepath, str):
with open(filepath, mode='r') as ical_file:
ical = (Calendar.from_ical(ical_file.read()))
self.icalendars += ical
else: else:
raise Exception (f"Input: '{filepath}' is not a string or list!") raise Exception (f"Input: '{filepath}' is not a string or list!")
self.icalendars += ical
logger.info('loaded iCalendars from filepaths') logger.info('loaded iCalendars from filepaths')
def get_events(self, timeline_start, timeline_end, timezone=None): def get_events(self, timeline_start, timeline_end, timezone=None):