container: hledger-flow: trezor: add v25.9.1+ FS / backward compat

This commit is contained in:
2026-03-17 14:06:45 -07:00
parent 484d01aa7a
commit a09bf1c726

View File

@@ -36,16 +36,35 @@ source "${DOCKER_FINANCE_CONTAINER_REPO}/src/hledger-flow/lib/lib_preprocess.bas
[ -z "$global_in_filename" ] && exit 1 [ -z "$global_in_filename" ] && exit 1
function reseat_fs()
{
[ -z $1 ] && exit 1
local -r _fs="$1"
local -r _header="Timestamp${_fs}Date${_fs}Time${_fs}Type${_fs}Transaction ID${_fs}Fee${_fs}Fee unit${_fs}Address${_fs}Label${_fs}Amount${_fs}Amount unit${_fs}Fiat (USD)${_fs}Other"
echo "$_header"
}
function parse() function parse()
{ {
lib_preprocess::assert_header "Timestamp;Date;Time;Type;Transaction ID;Fee;Fee unit;Address;Label;Amount;Amount unit;Fiat (USD);Other" local _gawk=("gawk")
local _fs _header
_header="$(reseat_fs ";")"
if lib_preprocess::test_header "$_header"; then
_fs="FS=;"
else
# Since v25.9.1
_header="$(reseat_fs ",")"
lib_preprocess::assert_header "$_header"
_gawk+=("--csv")
fi
# Get subaccount(s) from filename # Get subaccount(s) from filename
local _subaccount local _subaccount
_subaccount="$(echo $global_in_filename | cut -d'_' -f1)" _subaccount="$(echo $global_in_filename | cut -d'_' -f1)"
# NOTE: subaccount (account label) is entered within the app # NOTE: subaccount (account label) is entered within the app
gawk \ "${_gawk[@]}" \
-v global_year="$global_year" \ -v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \ -v global_subaccount="$global_subaccount" \
-v subaccount="$_subaccount" \ -v subaccount="$_subaccount" \
@@ -64,7 +83,7 @@ function parse()
# skip # Date (N/A) # skip # Date (N/A)
# skip # Time (N/A) # skip # Time (N/A)
# Type # TODO: are there more types? # Type (TODO: are there more types?)
direction=($4 ~ /^RECV$/ ? "IN" : "OUT") direction=($4 ~ /^RECV$/ ? "IN" : "OUT")
printf $4 OFS printf $4 OFS
@@ -80,7 +99,19 @@ function parse()
printf("%.8f", $10); printf OFS # Amount # TODO: more than 8 places for Ethereum, etc.? printf("%.8f", $10); printf OFS # Amount # TODO: more than 8 places for Ethereum, etc.?
printf "\"" $11 "\"" OFS # Amount unit printf "\"" $11 "\"" OFS # Amount unit
printf "\"" $12 "\"" OFS # Fiat (USD)
# Fiat (USD)
# NOTE: is already quoted since v25.9.1
fiat=$12
if (fiat ~ /^"/)
{
printf fiat OFS
}
else
{
printf "\"" fiat "\"" OFS
}
printf "\"" $13 "\"" OFS # Other printf "\"" $13 "\"" OFS # Other
printf direction OFS printf direction OFS
@@ -88,7 +119,7 @@ function parse()
printf "\n" printf "\n"
}' FS=\; OFS=, "$global_in_path" >"$global_out_path" }' "$_fs" OFS=, "$global_in_path" >"$global_out_path"
} }
function main() function main()