Created update script for ledger-cli using simplefin

This commit is contained in:
Random936
2025-12-01 16:28:02 -05:00
parent 434c84caf6
commit b0d8421b70
3 changed files with 61 additions and 0 deletions

21
ledger/setup.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
read -p "Enter your setup token: " token
while : ; do
read -sp "Enter password: " password
echo
read -sp "Confirm password: " confirmed
echo
[[ "$password" == "$confirmed" ]] && break || echo "Passwords are not equal."
echo
done
CLAIM_URL="$(echo "$token" | base64 -d)"
ACCESS_URL="$(curl -H "Content-Length: 0" -X POST "$CLAIM_URL")"
echo "Claim URL: $CLAIM_URL"
echo "Access URL: $ACCESS_URL"
echo "$ACCESS_URL" | openssl aes-256-cbc -salt -a -pbkdf2 -iter 1000000 -pass "pass:$password" > ~/.simplefin.enc

23
ledger/update.jq Normal file
View File

@@ -0,0 +1,23 @@
def format_transactions:
map(
.name as $name |
.transactions |
map(.account = $name)[]
) |
sort_by(.transacted_at) |
map(
(.transacted_at | strftime("%Y/%m/%d")) + " " +
(.description | gsub("\\s+"; " ")) + "\n UNKNOWN $" +
(-(.amount | tonumber) | tostring) + " ; Payee: " +
.payee + "\n " +
.account + "\n"
);
def rename_accounts:
map(.name |= (
if (.| startswith("Adv Plus Banking")) then "Checking"
elif (.| startswith("Unlimited Cash Rewards Visa Signature")) then "Credit"
elif (.| startswith("Amazon Prime Rewards Visa Signature")) then "Amazon"
end));
.accounts | rename_accounts | format_transactions[]

17
ledger/update.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
if [[ $# < 1 ]]; then
echo "Usage: $0 <start-date>"
exit
fi
if [[ -f "~/.simplefin.enc" ]]; then
echo "Simplefin access URL is missing."
echo "Please run the setup script before running update."
exit
fi
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
ACCESS_URL="$(cat ~/.simplefin.enc | openssl aes-256-cbc -d -a -salt -pbkdf2 -iter 1000000)"
curl -L "${ACCESS_URL}/accounts?start-date=$(date -d "$1" '+%s')&pending=1" | jq -r -f "${SCRIPT_DIR}/update.jq"