Skip to content
16 changes: 11 additions & 5 deletions src/chronos/calendar_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, app_config: Config):
self.default_location = None

self.tags_excluded = []
self.exclude_event_by_strings_in_summary = []

self.sanitize = {"stati": True, "source_icons": True, "target_icons": True}

Expand Down Expand Up @@ -134,8 +135,9 @@ def read_ics_from_url(self):
new_chronos_event._ics_event = event.copy()

# Only handle public events and those not containing exclude tags
is_viable_event = not new_chronos_event.is_confidential and not new_chronos_event.is_excluded and not new_chronos_event.date_out_of_range
if not is_viable_event:
is_invalid_event = new_chronos_event.is_confidential or new_chronos_event.is_excluded or new_chronos_event.date_out_of_range
if is_invalid_event:
logger.info(f"Skipping further ical parsing on confidential or excluded event: {new_chronos_event.uid} | Source: {self.cal_name}")
continue

new_chronos_event.populate_from_vcal_object()
Expand Down Expand Up @@ -275,9 +277,13 @@ def read_event(self, calEvent: caldav.Event) -> None:
chronos_event.calDAV = calEvent

# Only handle public events and those not conataining exclude tags
if not chronos_event.is_confidential and not chronos_event.is_excluded and not chronos_event.date_out_of_range:
chronos_event.populate_from_vcal_object()
self.events_data[chronos_event.key] = chronos_event
is_invalid_event = chronos_event.is_confidential or chronos_event.is_excluded or chronos_event.date_out_of_range
if is_invalid_event:
logger.info(f"Skipping further ical parsing on confidential or excluded event: {chronos_event.uid} | Source: {self.cal_name}")
continue

chronos_event.populate_from_vcal_object()
self.events_data[chronos_event.key] = chronos_event

def search_events_by_tags(self, tags: list) -> dict:
"""search read events created by chronos with given tags
Expand Down
13 changes: 10 additions & 3 deletions src/chronos/chronos_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,16 @@ def is_confidential(self) -> bool:

@property
def is_excluded(self) -> bool:
setEventCats = set(map(lambda x: x.lower(), self.categories))
setExclude = set(map(lambda x: x.lower(), self.source.tags_excluded))
do_exclude = not (setExclude.isdisjoint(setEventCats))
set_of_event_categories = set(map(lambda x: x.lower(), self.categories))
set_of_excluded_tags = set(map(lambda x: x.lower(), self.source.tags_excluded))
do_exclude_by_tag = not (set_of_excluded_tags.isdisjoint(set_of_event_categories))

do_exclude_by_string_in_summary = False
for the_string in self.source.exclude_event_by_strings_in_summary:
if the_string.lower() in self.title.lower():
do_exclude_by_string_in_summary = True

do_exclude = do_exclude_by_tag or do_exclude_by_string_in_summary
return do_exclude

@property
Expand Down