From 547dac8562222dbd25ff60877e1439f6e723fc32 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sun, 3 Mar 2019 13:53:22 +0100 Subject: [PATCH] Implemented new abstraction level of interface --- Calendar/IcalEvents.py | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/Calendar/IcalEvents.py b/Calendar/IcalEvents.py index 826a255..ef7d5e3 100644 --- a/Calendar/IcalEvents.py +++ b/Calendar/IcalEvents.py @@ -12,10 +12,10 @@ class IcalEvents(CalendarInterface): """Fetches events from ical addresses.""" def __init__(self, urls): self.urls = urls - self.__load_events_from_urls__() + super(IcalEvents, self).__init__() - def __load_events_from_urls__(self): - self.loaded_events = [] + def __get_events__(self): + loaded_events = [] try: for calendar in self.urls: decode = str(urlopen(calendar).read().decode()) @@ -32,38 +32,11 @@ class IcalEvents(CalendarInterface): cal_event.description = event.description cal_event.location= event.location - self.loaded_events.append(cal_event) + loaded_events.append(cal_event) + return loaded_events except: - return + return [] def __fix_errors__(self, decode): return decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') \ - .replace('BEGIN:VALARM\r\nACTION:EMAIL','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') - - def get_upcoming_events(self): - return self.__get_events_to_filter__(lambda x : (x.begin_datetime - datetime.now(timezone.utc)) > timedelta(0)) - - def get_today_events(self): - return self.get_day_events(datetime.now(timezone.utc)) - - def get_day_events(self, date): - return self.__get_events_to_filter__(lambda x : x.begin_datetime.strftime('%d-%m-%y') == date.strftime('%d-%m-%y')) - - def get_month_events(self, month = -1): - if month < 0: - month = datetime.now().month - return self.__get_events_to_filter__(lambda x : x.begin_datetime.month == month) - - def get_week_events(self, week = -1): - if week < 0 and week_starts_on == "Monday": - week = int(datetime.now().strftime('%W')) + 1 - elif week < 0: - week = int(datetime.now().strftime('%U')) + 1 - - if week_starts_on == "Monday": - return self.__get_events_to_filter__(lambda x : int(x.begin_datetime.strftime('%W')) + 1 == week) - else: - return self.__get_events_to_filter__(lambda x : int(x.begin_datetime.strftime('%U')) + 1 == week) - - def __get_events_to_filter__(self, event_filter): - return [event for event in self.loaded_events if event_filter(event)] \ No newline at end of file + .replace('BEGIN:VALARM\r\nACTION:EMAIL','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') \ No newline at end of file