From e1e25e3d2a353ae624a0f4da3ccfea63d0220a58 Mon Sep 17 00:00:00 2001 From: Max G Date: Sun, 10 Mar 2019 18:32:20 +0100 Subject: [PATCH] Added functionality to add highlighted calendars --- Calendar/E-Paper.py | 2 +- Calendar/IcalEvents.py | 23 ++++++++++++++++++++--- Calendar/settings.py.sample | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index e6df861..5cbff1c 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -70,7 +70,7 @@ def main (): design.add_weather(owm) debug.print_line('Fetching events from your calendar') - events_cal = IcalEvents.IcalEvents(ical_urls) + events_cal = IcalEvents.IcalEvents(ical_urls, highlighted_ical_urls) design.add_calendar(events_cal) debug.print_line('Fetching posts from your rss-feeds') diff --git a/Calendar/IcalEvents.py b/Calendar/IcalEvents.py index 0517e82..238b722 100644 --- a/Calendar/IcalEvents.py +++ b/Calendar/IcalEvents.py @@ -10,14 +10,31 @@ except Exception as e: class IcalEvents(CalendarInterface): """Fetches events from ical addresses.""" - def __init__(self, urls): + def __init__(self, urls, highlighted_urls=None): self.urls = urls + self.highlighted_urls = highlighted_urls super(IcalEvents, self).__init__() def __get_events__(self): + events = self.__get_events_from_urls__(self.urls) + + highlighted = self.__get_events_from_urls__(self.highlighted_urls) + map(self.__highlight_event__, highlighted) + events.extend(highlighted) + + return events + + def __highlight_event__(self, event): + event.highlight = True + return event + + def __get_events_from_urls__(self, urls): loaded_events = [] try: - for calendar in self.urls: + if urls is None: + return loaded_events + + for calendar in urls: decode = str(urlopen(calendar).read().decode()) fixed_decode = self.__fix_errors__(decode) @@ -36,7 +53,7 @@ class IcalEvents(CalendarInterface): loaded_events.append(cal_event) return loaded_events except: - return [] + return loaded_events def __fix_errors__(self, decode): return decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') \ diff --git a/Calendar/settings.py.sample b/Calendar/settings.py.sample index a47e830..f6ffbef 100644 --- a/Calendar/settings.py.sample +++ b/Calendar/settings.py.sample @@ -4,6 +4,9 @@ ical_urls = [ "https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics" ] +highlighted_ical_urls = [ +] + rss_feeds = [ "http://feeds.bbci.co.uk/news/world/rss.xml#" ]