예제 #1
0
파일: __init__.py 프로젝트: scjtqs/BGmi
def episode_filter_regex(data: List[Episode], regex: str = None) -> List[Episode]:
    """

    :param data: list of bangumi dict
    :param regex: regex
    """
    if regex:
        try:
            match = re.compile(regex)
            data = [s for s in data if match.findall(s.title)]
        except re.error as e:
            if os.getenv("DEBUG"):  # pragma: no cover
                import traceback

                traceback.print_exc()
                raise e
            return data

    if not ENABLE_GLOBAL_FILTER == "0":
        data = list(
            filter(
                lambda s: all(
                    map(
                        lambda t: t.strip().lower() not in s.title.lower(),
                        GLOBAL_FILTER.split(","),
                    )
                ),
                data,
            )
        )

    return data
예제 #2
0
def episode_filter_regex(data: List[Episode],
                         regex: str = None) -> List[Episode]:
    """

    :param data: list of bangumi dict
    :param regex: regex
    """
    if regex:
        try:
            match = re.compile(regex)
            data = [s for s in data if match.findall(s.title)]
        except re.error as e:
            if os.getenv("DEBUG"):  # pragma: no cover
                traceback.print_exc()
                raise e
            print_warning(
                f"can't compile regex {regex}, skipping filter by regex")

    if ENABLE_GLOBAL_FILTER != "0":
        exclude_keywords = [
            t.strip().lower() for t in GLOBAL_FILTER.split(",")
        ]
        data = [x for x in data if not x.contains_any_words(exclude_keywords)]

    return data
예제 #3
0
파일: base.py 프로젝트: zhkrb/BGmi
    def filter_keyword(data, regex=None):
        """

        :type regex: str
        :param data: list of bangumi dict
        :type data: list[dict]
        """
        if regex:
            try:
                match = re.compile(regex)
                data = [s for s in data if match.findall(s['title'])]
            except re.error as e:
                if os.getenv('DEBUG'):  # pragma: no cover
                    import traceback
                    traceback.print_exc()
                    raise e
                return data

        if not ENABLE_GLOBAL_FILTER == '0':
            data = list(
                filter(
                    lambda s: all(
                        map(
                            lambda t: t.strip().lower() not in s['title'].
                            lower(), GLOBAL_FILTER.split(','))), data))

        return data
예제 #4
0
파일: base.py 프로젝트: canbion/BGmi
    def filter_keyword(self, data, regex=None):
        if regex:
            try:
                match = re.compile(regex)
                data = list(
                    filter(
                        lambda s: True
                        if match.findall(s['title']) else False, data))
            except re.error as e:
                if os.getenv('DEBUG'):  # pragma: no cover
                    import traceback
                    traceback.print_exc()
                    raise e
                return data

        if not ENABLE_GLOBAL_FILTER == '0':
            data = list(
                filter(
                    lambda s: True if all(
                        map(
                            lambda t: t.strip().lower() not in s['title'].
                            lower(), GLOBAL_FILTER.split(','))) else False,
                    data))

        return data