From b0d8421b70e0617cf6cb1c586eaba25cc7217b71 Mon Sep 17 00:00:00 2001 From: Random936 Date: Mon, 1 Dec 2025 16:28:02 -0500 Subject: [PATCH] Created update script for ledger-cli using simplefin --- ledger/setup.sh | 21 +++++++++++++++++++++ ledger/update.jq | 23 +++++++++++++++++++++++ ledger/update.sh | 17 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 ledger/setup.sh create mode 100644 ledger/update.jq create mode 100644 ledger/update.sh diff --git a/ledger/setup.sh b/ledger/setup.sh new file mode 100644 index 0000000..1830886 --- /dev/null +++ b/ledger/setup.sh @@ -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 + diff --git a/ledger/update.jq b/ledger/update.jq new file mode 100644 index 0000000..cdd0d05 --- /dev/null +++ b/ledger/update.jq @@ -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[] \ No newline at end of file diff --git a/ledger/update.sh b/ledger/update.sh new file mode 100644 index 0000000..b57a9e9 --- /dev/null +++ b/ledger/update.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +if [[ $# < 1 ]]; then + echo "Usage: $0 " + 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"