fixing things

This commit is contained in:
Kyattsukuro 2026-04-02 13:35:25 +02:00
parent cf4010c015
commit ce4efded12
7 changed files with 14 additions and 10 deletions

View File

@ -31,7 +31,8 @@ COL_INSTRUCTIONS = {
"command": "REGEX_MOVE_TO_COL", "command": "REGEX_MOVE_TO_COL",
"with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to" "with_input_iteration": list(CATCHED_BY.keys()), # Moves matching group {{% 1 %}} to "to"
"match": r"^.*({{% 0 %}}),?(?:.*+)*$", "match": r"^.*({{% 0 %}}),?(?:.*+)*$",
"to": "Fangart" "to": "Fangart",
"copy": True
} }
], ],
("Anzahl",): [{ ("Anzahl",): [{

View File

@ -316,6 +316,7 @@ CATCHED_BY = {
"Nfg": [*add_cased_options("nfg"), "Nfg": [*add_cased_options("nfg"),
*add_cased_options("nf")], *add_cased_options("nf")],
"KK": [*add_cased_options("kk"), "KK": [*add_cased_options("kk"),
*add_cased_options(" k "),
*add_cased_options("überwinterungskästen"), *add_cased_options("überwinterungskästen"),
*add_cased_options("kastenkontrolle"), *add_cased_options("kastenkontrolle"),
*add_cased_options("kasten")], *add_cased_options("kasten")],

View File

@ -59,7 +59,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if args.v: if args.v:
print("1.4") print("1.5")
return return
if not args.type: if not args.type:
parser.error("The --type argument is required.") parser.error("The --type argument is required.")

View File

@ -1,4 +1,3 @@
import re
from fledermaus_formatter.table_handler.Entry import Entry from fledermaus_formatter.table_handler.Entry import Entry
from copy import deepcopy from copy import deepcopy
@ -13,7 +12,6 @@ class FindAndReplace:
for correct_name, bad_names in self.map.items(): for correct_name, bad_names in self.map.items():
for bad_name in bad_names: for bad_name in bad_names:
if self.require_full_match and bad_name == res: if self.require_full_match and bad_name == res:
# Todo remove random leading/trailing spaces before if
res = correct_name res = correct_name
break break
elif not self.require_full_match: elif not self.require_full_match:

View File

@ -3,9 +3,10 @@ import re
from fledermaus_formatter.table_handler.Entry import Entry from fledermaus_formatter.table_handler.Entry import Entry
class RegexMoveToCol: class RegexMoveToCol:
def __init__(self, match: str, to: str, with_input_iteration: list[list[str]]|None = None): def __init__(self, match: str, to: str, with_input_iteration: list[list[str]]|None = None, copy: bool = False):
self.match = match self.match = match
self.to = to self.to = to
self.copy = copy
if with_input_iteration is not None: if with_input_iteration is not None:
with_input_iteration = ( with_input_iteration = (
@ -65,13 +66,16 @@ class RegexMoveToCol:
def execute_on_row(self, row: dict[str, str], source_coll: str = None): def execute_on_row(self, row: dict[str, str], source_coll: str = None):
if not source_coll: if not source_coll:
raise ValueError("source_col required") raise ValueError("source_col required")
changes = {}
if self.with_input_iteration: if self.with_input_iteration:
changes = {}
for iteration in self.with_input_iteration: for iteration in self.with_input_iteration:
used_regex = self.match used_regex = self.match
for operation_id in range(0, self.__operation_input_depth): for operation_id in range(0, self.__operation_input_depth):
used_regex = used_regex.replace(f"{{{{% {operation_id} %}}}}", iteration[operation_id]) used_regex = used_regex.replace(f"{{{{% {operation_id} %}}}}", iteration[operation_id])
changes = self.do_changes(source_coll, used_regex, row, changes) changes = self.do_changes(source_coll, used_regex, row, changes)
return changes
else: else:
return self.do_changes(source_coll, self.match, row) changes = self.do_changes(source_coll, self.match, row)
if self.copy and source_coll in changes:
del changes[source_coll]
return changes

View File

@ -32,7 +32,7 @@ class RowColorToCalue:
def _check_if_collection_matchers(self, collectin: dict[tuple[int, int, int]], color_place: str) -> bool: def _check_if_collection_matchers(self, collectin: dict[tuple[int, int, int]], color_place: str) -> bool:
threshold_sq = 120 threshold_sq = 80
res_map = [] res_map = []
if self.approximate: if self.approximate:

View File

@ -105,7 +105,7 @@ class TableSerializer:
case "FIND_AND_REPLACE": case "FIND_AND_REPLACE":
res = FindAndReplace(instruct["map"], instruct.get("reqire_full_match", False)).execute_on_cell(in_place_working_row[source_cell]) res = FindAndReplace(instruct["map"], instruct.get("reqire_full_match", False)).execute_on_cell(in_place_working_row[source_cell])
case "REGEX_MOVE_TO_COL": case "REGEX_MOVE_TO_COL":
res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \ res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration"), instruct.get("copy", False)) \
.execute_on_row(in_place_working_row, source_cell) .execute_on_row(in_place_working_row, source_cell)
case "REGEX_EDIT_COL": case "REGEX_EDIT_COL":
res = RegexEditCol(instruct["match"], instruct["replace_with"], instruct.get("matching_group_rearange"), instruct.get("match_none"))\ res = RegexEditCol(instruct["match"], instruct["replace_with"], instruct.get("matching_group_rearange"), instruct.get("match_none"))\