filters.py 1.29 KB
Newer Older
erdnaxe's avatar
erdnaxe committed
1
import logging
erdnaxe's avatar
erdnaxe committed
2 3 4 5 6
import re
from datetime import date

from icalendar_tools import get_event_start_date

erdnaxe's avatar
erdnaxe committed
7 8
logger = logging.getLogger('Filters')

erdnaxe's avatar
erdnaxe committed
9 10 11 12 13 14 15 16 17

def filter_date(event) -> bool:
    """Return true if event day is today or in the future"""
    event_date = get_event_start_date(event)

    if event_date:
        return event_date >= date.today()
    else:
        # If there is a bug in data then do not filter
erdnaxe's avatar
erdnaxe committed
18 19
        summary = event.get('summary')
        logger.warn('There was an issue with the date of {}'.format(summary))
erdnaxe's avatar
erdnaxe committed
20 21 22 23 24 25 26 27 28
        return True


def filter_group(event, selected_groups) -> bool:
    """Filter group according to the group selected"""
    summary = event.get('summary')
    summary_search = re.search('([0-9]{3}) - ([A-Z]{2}) \(grpe : ([^\)]*)\)', summary, re.IGNORECASE)

    if summary_search:
erdnaxe's avatar
erdnaxe committed
29 30 31 32
        ue, group = 'ue_' + summary_search.group(1), summary_search.group(3)
        if ue in selected_groups:
            # UE is configured
            if group in selected_groups[ue]:
erdnaxe's avatar
erdnaxe committed
33 34 35 36
                # Group was selected
                return True
            else:
                # Group is not the one selected
erdnaxe's avatar
erdnaxe committed
37
                logger.info('Removed {} because it had not been chosen'.format(summary))
erdnaxe's avatar
erdnaxe committed
38 39 40 41
                return False

    # If there is not a group specified do not filter
    return True