filters.py 1005 Bytes
Newer Older
erdnaxe's avatar
erdnaxe committed
1
import logging
erdnaxe's avatar
erdnaxe committed
2 3
import re

erdnaxe's avatar
erdnaxe committed
4 5
logger = logging.getLogger('Filters')

erdnaxe's avatar
erdnaxe committed
6

7
def group(event, selected_groups) -> bool:
erdnaxe's avatar
erdnaxe committed
8 9
    """Filter group according to the group selected"""
    summary = event.get('summary')
10
    date = event.get('dtstart').dt.strftime("%Y-%m-%d")
erdnaxe's avatar
erdnaxe committed
11
    summary_search = re.search('([0-9]{3}) - ([A-Za-z ]*) \(grpe : ([^\)]*)\)',
12
                               summary, re.IGNORECASE)
erdnaxe's avatar
erdnaxe committed
13 14

    if summary_search:
15 16
        ue, groups = 'ue_' + summary_search.group(1), summary_search.group(
            3).split(' - ')
erdnaxe's avatar
erdnaxe committed
17 18
        if ue in selected_groups:
            # UE is configured
19 20 21 22
            for group in groups:
                if group in selected_groups[ue]:
                    # Group was selected
                    return True
23

24
            # Group is not the one selected
25
            logger.info(f"Remove '\033[1;1m{summary}\033[1;0m' (on \033[1;1m{date}\033[1;0m) because it had not been chosen")
26
            return False
erdnaxe's avatar
erdnaxe committed
27 28 29

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