add exclude_regex

This commit is contained in:
Raqueebuddin Aziz
2024-04-07 22:50:48 +05:30
parent 48ea1aa14f
commit cc8c5d187f
2 changed files with 10 additions and 1 deletions
+2 -1
View File
@@ -30,7 +30,8 @@ The files should end in `.txt` and each value should be on it's own line.
- `input_text(LIST)`: Choose a line from the files yourself or select `*` to choose at random using seed.
- `prefix(STRING)`: The prefix to use
- `suffix(STRING)`: The suffix to use
- `regex(STRING)`: If provided this will be used to filter the input files.
- `regex(STRING)`: If provided this will be used to filter the input files. case insensitive. only items that match will be used
- `exclude_regex(STRING)`: If provided this will be used to filter the input files. case insensitive. matched items will not be used
- `temp_override(STRING)`: If not blank then overrides the output.
- `output_blank_ratio(FLOAT)`: A number between 0 and 1 to determine if the output should be blank. Not used if temp_override is set.
+8
View File
@@ -11,6 +11,7 @@ files = list(
wildcards_directory.glob("**/*.txt")
| map(lambda x: x.relative_to(wildcards_directory))
)
item_map = dict()
def get_items_for_wildcard_path(glob: str):
@@ -56,6 +57,10 @@ class SimpleWildcard:
"STRING",
{"default": ".*"},
),
"exclude_regex": (
"STRING",
{"default": ""},
),
"temp_override": (
"STRING",
{"default": ""},
@@ -104,6 +109,9 @@ class SimpleWildcard:
if kwargs["regex"] != ".*" or kwargs["regex"] != "":
regex = re.compile(kwargs["regex"], re.IGNORECASE)
items = list(items | where(regex.match))
if kwargs["exclude_regex"] != "":
regex = re.compile(kwargs["exclude_regex"], re.IGNORECASE)
items = list(items | where(lambda x: not regex.match(x)))
has_items = len(items) > 0
if has_items: