|
@@ -1,3 +1,4 @@
|
|
|
|
|
+# https://github.com/LmeSzinc/AzurLaneAutoScript/blob/master/module/base/filter.py
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
|
from module.logger import logger
|
|
from module.logger import logger
|
|
@@ -20,8 +21,22 @@ class Filter:
|
|
|
self.filter = []
|
|
self.filter = []
|
|
|
|
|
|
|
|
def load(self, string):
|
|
def load(self, string):
|
|
|
|
|
+ """
|
|
|
|
|
+ Load a filter string, filters are connected with ">"
|
|
|
|
|
+
|
|
|
|
|
+ There are also tons of unicode characters similar to ">"
|
|
|
|
|
+ > \u003E correct
|
|
|
|
|
+ > \uFF1E
|
|
|
|
|
+ ﹥ \uFE65
|
|
|
|
|
+ › \u203a
|
|
|
|
|
+ ˃ \u02c3
|
|
|
|
|
+ ᐳ \u1433
|
|
|
|
|
+ ❯ \u276F
|
|
|
|
|
+ """
|
|
|
string = str(string)
|
|
string = str(string)
|
|
|
- self.filter_raw = [f.strip(' \t\r\n') for f in string.split('>')]
|
|
|
|
|
|
|
+ string = re.sub(r'[ \t\r\n]', '', string)
|
|
|
|
|
+ string = re.sub(r'[>﹥›˃ᐳ❯]', '>', string)
|
|
|
|
|
+ self.filter_raw = string.split('>')
|
|
|
self.filter = [self.parse_filter(f) for f in self.filter_raw]
|
|
self.filter = [self.parse_filter(f) for f in self.filter_raw]
|
|
|
|
|
|
|
|
def is_preset(self, filter):
|
|
def is_preset(self, filter):
|
|
@@ -31,7 +46,7 @@ class Filter:
|
|
|
"""
|
|
"""
|
|
|
Args:
|
|
Args:
|
|
|
objs (list): List of objects and strings
|
|
objs (list): List of objects and strings
|
|
|
- func (callable): A function to filter object.
|
|
|
|
|
|
|
+ func (callable): A function that to filter object.
|
|
|
Function should receive an object as arguments, and return a bool.
|
|
Function should receive an object as arguments, and return a bool.
|
|
|
True means add it to output.
|
|
True means add it to output.
|
|
|
|
|
|
|
@@ -62,6 +77,19 @@ class Filter:
|
|
|
|
|
|
|
|
return out
|
|
return out
|
|
|
|
|
|
|
|
|
|
+ def applys(self, objs, funcs):
|
|
|
|
|
+ """
|
|
|
|
|
+ Args:
|
|
|
|
|
+ objs (list): List of objects and strings
|
|
|
|
|
+ List[func(callable)] : A list of funciton that to filter object.
|
|
|
|
|
+ Function should receive an object as arguments, and return a bool.
|
|
|
|
|
+ True means add it to output.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ list: A list of objects and preset strings, such as [object, object, object, 'reset']
|
|
|
|
|
+ """
|
|
|
|
|
+ return self.apply(objs, func=lambda x: all(func(x)for func in funcs))
|
|
|
|
|
+
|
|
|
def apply_filter_to_obj(self, obj, filter):
|
|
def apply_filter_to_obj(self, obj, filter):
|
|
|
"""
|
|
"""
|
|
|
Args:
|
|
Args:
|
|
@@ -100,4 +128,4 @@ class Filter:
|
|
|
logger.warning(f'Invalid filter: "{string}". This selector does not match the regex, nor a preset.')
|
|
logger.warning(f'Invalid filter: "{string}". This selector does not match the regex, nor a preset.')
|
|
|
# Invalid filter will be ignored.
|
|
# Invalid filter will be ignored.
|
|
|
# Return strange things and make it impossible to match
|
|
# Return strange things and make it impossible to match
|
|
|
- return ['1nVa1d'] + [None] * (len(self.attr) - 1)
|
|
|
|
|
|
|
+ return ['1nVa1d'] + [None] * (len(self.attr) - 1)
|