container: hledger-flow: gemini: add uniform quotes

- Allows undesirable characters in variable-text columns
- Related refactoring
This commit is contained in:
2026-02-13 11:19:35 -08:00
parent 3764376bfa
commit 3666baed83

View File

@@ -2,7 +2,7 @@
# docker-finance | modern accounting for the power-user # docker-finance | modern accounting for the power-user
# #
# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) # Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -198,8 +198,10 @@ function parse_trades()
local _account_currency local _account_currency
_account_currency="$(echo $global_in_filename | cut -d"-" -f1 | sed 's:...$::')" _account_currency="$(echo $global_in_filename | cut -d"-" -f1 | sed 's:...$::')"
gawk -v account_currency="$_account_currency" \ gawk --csv \
-v global_year="$global_year" -v global_subaccount="$global_subaccount" \ -v account_currency="$_account_currency" \
-v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \
'{ '{
if (NR<2) if (NR<2)
next next
@@ -212,9 +214,13 @@ function parse_trades()
printf $9 OFS # UID (tid) printf $9 OFS # UID (tid)
printf date OFS # Date printf date OFS # Date
printf "TRADE" OFS # Type printf "TRADE" OFS # Type
printf $5 OFS # OrderType (type) printf "\"" $5 "\"" OFS # OrderType (type)
printf toupper(account_currency) OFS # CurrencyOne (account_currency)
printf $7 OFS # CurrencyTwo (fee_currency) # CurrencyOne (account_currency)
printf "\"" toupper(account_currency) "\"" OFS
# CurrencyTwo (fee_currency)
printf "\"" $7 "\"" OFS
# TODO: getline an gawk remove-zeros script # TODO: getline an gawk remove-zeros script
amount=sprintf("%.8f", $2) amount=sprintf("%.8f", $2)
@@ -271,14 +277,17 @@ function parse_trades()
printf "\n" printf "\n"
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function parse_earn() function parse_earn()
{ {
lib_preprocess::assert_header "earnTransactionId,transactionId,transactionType,amountCurrency,amount,priceCurrency,priceAmount,dateTime" lib_preprocess::assert_header "earnTransactionId,transactionId,transactionType,amountCurrency,amount,priceCurrency,priceAmount,dateTime"
gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" -M -v PREC=100 \ gawk --csv \
-v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \
-M -v PREC=100 \
'{ '{
if (NR<2) if (NR<2)
next next
@@ -292,7 +301,7 @@ function parse_earn()
printf date OFS # Date printf date OFS # Date
printf "INTEREST" OFS # Type printf "INTEREST" OFS # Type
printf "EARN" OFS # OrderType (type) printf "EARN" OFS # OrderType (type)
printf $4 OFS # CurrencyOne (amountCurrency) printf "\"" $4 "\""OFS # CurrencyOne (amountCurrency)
printf OFS # CurrencyTwo printf OFS # CurrencyTwo
# Amount # Amount
@@ -329,14 +338,16 @@ function parse_earn()
printf "\n"; printf "\n";
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function parse_card() function parse_card()
{ {
lib_preprocess::assert_header "Reference Number,Transaction Post Date,Description of Transaction,Transaction Type,Amount" lib_preprocess::assert_header "Reference Number,Transaction Post Date,Description of Transaction,Transaction Type,Amount"
gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \ gawk --csv \
-v global_year="$global_year" \
-v global_subaccount="$global_subaccount" \
'{ '{
if (NR<2) if (NR<2)
next next
@@ -350,8 +361,13 @@ function parse_card()
printf $1 OFS # Reference Number printf $1 OFS # Reference Number
printf $2 OFS # Transaction Post Date printf $2 OFS # Transaction Post Date
printf $3 OFS # Description of Transaction
printf $4 OFS # Transaction Type # Description of Transaction
gsub(/%/, "%%", $3)
gsub(/"/, "", $3)
printf "\"" $3 "\"" OFS
printf "\"" $4 "\"" OFS # Transaction Type
printf $5 OFS # Amount printf $5 OFS # Amount
direction=($5 ~ /^-/ ? "IN" : "OUT") direction=($5 ~ /^-/ ? "IN" : "OUT")
@@ -361,7 +377,7 @@ function parse_card()
printf "\n"; printf "\n";
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function main() function main()