Added functionality to add highlighted calendars
This commit is contained in:
parent
895a7cda1c
commit
e1e25e3d2a
3 changed files with 24 additions and 4 deletions
|
@ -70,7 +70,7 @@ def main ():
|
||||||
design.add_weather(owm)
|
design.add_weather(owm)
|
||||||
|
|
||||||
debug.print_line('Fetching events from your calendar')
|
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)
|
design.add_calendar(events_cal)
|
||||||
|
|
||||||
debug.print_line('Fetching posts from your rss-feeds')
|
debug.print_line('Fetching posts from your rss-feeds')
|
||||||
|
|
|
@ -10,14 +10,31 @@ except Exception as e:
|
||||||
|
|
||||||
class IcalEvents(CalendarInterface):
|
class IcalEvents(CalendarInterface):
|
||||||
"""Fetches events from ical addresses."""
|
"""Fetches events from ical addresses."""
|
||||||
def __init__(self, urls):
|
def __init__(self, urls, highlighted_urls=None):
|
||||||
self.urls = urls
|
self.urls = urls
|
||||||
|
self.highlighted_urls = highlighted_urls
|
||||||
super(IcalEvents, self).__init__()
|
super(IcalEvents, self).__init__()
|
||||||
|
|
||||||
def __get_events__(self):
|
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 = []
|
loaded_events = []
|
||||||
try:
|
try:
|
||||||
for calendar in self.urls:
|
if urls is None:
|
||||||
|
return loaded_events
|
||||||
|
|
||||||
|
for calendar in urls:
|
||||||
decode = str(urlopen(calendar).read().decode())
|
decode = str(urlopen(calendar).read().decode())
|
||||||
fixed_decode = self.__fix_errors__(decode)
|
fixed_decode = self.__fix_errors__(decode)
|
||||||
|
|
||||||
|
@ -36,7 +53,7 @@ class IcalEvents(CalendarInterface):
|
||||||
loaded_events.append(cal_event)
|
loaded_events.append(cal_event)
|
||||||
return loaded_events
|
return loaded_events
|
||||||
except:
|
except:
|
||||||
return []
|
return loaded_events
|
||||||
|
|
||||||
def __fix_errors__(self, decode):
|
def __fix_errors__(self, decode):
|
||||||
return decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') \
|
return decode.replace('BEGIN:VALARM\r\nACTION:NONE','BEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:') \
|
||||||
|
|
|
@ -4,6 +4,9 @@ ical_urls = [
|
||||||
"https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics"
|
"https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
highlighted_ical_urls = [
|
||||||
|
]
|
||||||
|
|
||||||
rss_feeds = [
|
rss_feeds = [
|
||||||
"http://feeds.bbci.co.uk/news/world/rss.xml#"
|
"http://feeds.bbci.co.uk/news/world/rss.xml#"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue