Compare commits
No commits in common. "5797c693c47bb25cfa273b4e7fa8eaebefdb54c9" and "85fb5ea3c3a353467703d022343130d6ab3cfca2" have entirely different histories.
5797c693c4
...
85fb5ea3c3
@ -19,7 +19,6 @@ EXPECTED_OUTPUT_TABLE_SCHEMA.remove("Geschlecht")
|
||||
COL_INSTRUCTIONS = {
|
||||
("Art",): {
|
||||
"command": "FIND_AND_REPLACE",
|
||||
"reqire_full_match": True,
|
||||
"map": SPICIES
|
||||
},
|
||||
("Ort",): {
|
||||
|
||||
@ -23,13 +23,11 @@ COL_INSTRUCTIONS = {
|
||||
("Geschlecht",): [
|
||||
{
|
||||
"command": "FIND_AND_REPLACE",
|
||||
"map": REPRODUCTION,
|
||||
"reqire_full_match": True
|
||||
"map": REPRODUCTION
|
||||
},
|
||||
{
|
||||
"command": "FIND_AND_REPLACE",
|
||||
"map": AGE,
|
||||
"reqire_full_match": True
|
||||
"map": AGE
|
||||
},
|
||||
{
|
||||
"command": "REGEX_MOVE_TO_COL",
|
||||
|
||||
21
run.sh
21
run.sh
@ -2,25 +2,6 @@
|
||||
|
||||
SCRIPT_DIR="$HOME/.config/fledermaus-formatter"
|
||||
|
||||
to_absolute_args() {
|
||||
local result=()
|
||||
|
||||
for arg in "$@"; do
|
||||
if [ -e "$arg" ] || [ -d "$arg" ] || [ -f "$arg" ]; then
|
||||
result+=("$(realpath "$arg")")
|
||||
else
|
||||
result+=("$arg")
|
||||
fi
|
||||
done
|
||||
|
||||
printf '%s\n' "${result[@]}"
|
||||
}
|
||||
|
||||
ABS_ARGS=()
|
||||
while IFS= read -r line; do
|
||||
ABS_ARGS+=("$line")
|
||||
done < <(to_absolute_args "$@")
|
||||
|
||||
cd $SCRIPT_DIR
|
||||
source $SCRIPT_DIR/.venv/bin/activate
|
||||
$SCRIPT_DIR/.venv/bin/python3 __init__.py "${ABS_ARGS[@]}"
|
||||
$SCRIPT_DIR/.venv/bin/python3 __init__.py $@
|
||||
@ -2,18 +2,13 @@ import re
|
||||
from copy import deepcopy
|
||||
|
||||
class FindAndReplace:
|
||||
def __init__(self, map: dict[str, list[str]], reqire_full_match: bool = False):
|
||||
def __init__(self, map: dict[str, list[str]]):
|
||||
self.map = map
|
||||
self.require_full_match = reqire_full_match
|
||||
|
||||
def execute_on_cell(self, entry) -> str:
|
||||
res = deepcopy(entry.value)
|
||||
|
||||
for species, alternatives in self.map.items():
|
||||
for old_version in alternatives:
|
||||
if self.require_full_match and old_version == res:
|
||||
# Todo remove random leading/trailing spaces before if
|
||||
res = species
|
||||
else:
|
||||
res = res.replace(old_version, species)
|
||||
res = res.replace(old_version, species)
|
||||
return res
|
||||
@ -109,7 +109,7 @@ class TableSerializer:
|
||||
res_row = {}
|
||||
match instruct.get("command"):
|
||||
case "FIND_AND_REPLACE":
|
||||
res = FindAndReplace(instruct["map"], instruct.get("reqire_full_match", False)).execute_on_cell(row[source_cell])
|
||||
res = FindAndReplace(instruct["map"]).execute_on_cell(row[source_cell])
|
||||
case "REGEX_MOVE_TO_COL":
|
||||
res_row = RegexMoveToCol(instruct["match"], instruct["to"], instruct.get("with_input_iteration")) \
|
||||
.execute_on_row(row, source_cell)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user