enabled multiple values for one tag attribute

This commit is contained in:
Daniil Fajnberg 2021-07-25 17:33:06 +02:00
parent e92924e28a
commit 6a4efbd162
3 changed files with 10 additions and 5 deletions

View File

@ -53,7 +53,9 @@ target:
# Example:
#attrs:
#id: firstHeading
#class: foo
#class:
# - foo
# - example
#role: bar
# Filter using a custom python function with the path specified in dot-notation.

View File

@ -148,15 +148,18 @@ def tag_filter(tag: Tag, name: str = None, text: str = None, attrs: TagAttrs = N
return False
if not string_matches(tag.text, text, regex):
return False
for attr_name, attr_value in attrs.items():
for attr_name, attr_values in attrs.items():
try:
values = tag[attr_name]
except KeyError:
return False
if not isinstance(values, list):
values = [values]
if not any(string_matches(value, attr_value, regex) for value in values):
return False
if not isinstance(attr_values, list):
attr_values = [attr_values]
for attr_value in attr_values:
if not any(string_matches(value, attr_value, regex) for value in values):
return False
if func:
return func(tag)
return True

View File

@ -9,8 +9,8 @@ import yaml
from soupjobs import SOUPJOBS, CONFIG_FILE_ENV_VAR, CONFIG_FILE_PLACEHOLDER
TagAttrs = Dict[str, str]
StrListOrStr = Union[str, List[str]]
TagAttrs = Dict[str, StrListOrStr]
OptInt = Optional[int]
OptStr = Optional[str]
OptPyObj = Optional[PyObject]