From b5c4e9b594c3fe331f271dce2ab8e098576a15b5 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Wed, 30 Nov 2022 23:31:14 +1000 Subject: [PATCH] started on assertions bit --- readme.rst | 2 +- src/muneem/import.clj | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/readme.rst b/readme.rst index 7a76a66..f55d580 100644 --- a/readme.rst +++ b/readme.rst @@ -4,11 +4,11 @@ Muneem TODO ---- +- [ ] Create assertion for each ingest to ensure we're tracking correctly - [ ] Download NAB trade transactions and value - [ ] Download spaceship returns - [ ] MAYBE Mention uncategorized transactions in matrix chat so that i can categorize it - [ ] Post weekly spending in matrix chat -- [ ] Create assertion for each ingest to ensure we're tracking correctly DONE diff --git a/src/muneem/import.clj b/src/muneem/import.clj index 906f7c2..4292e5e 100644 --- a/src/muneem/import.clj +++ b/src/muneem/import.clj @@ -4,12 +4,14 @@ [cljc.java-time.local-date :as jt] [cljc.java-time.format.date-time-formatter :as pt] [clojure.java.shell :refer [sh]] + [clojure.string :as string] [clojure.string])) (def beancount-file "./documents/ledger.beancount") (def transaction-details (partial #(nth % 5))) (def category (partial #(nth % 7))) +(def balance (partial #(nth % 6))) (defn merchant-name [trans] (if (= (count trans) 9) (nth trans 8) @@ -365,6 +367,17 @@ [] (sh "cp" beancount-file "/home/anish/usr/finance/")) +(defn assert-balance + [transaction checking?] + (let [b (balance transaction) + account (if checking? + "Assets:Checking" + "Assets:Savings") + date (-> (sh "date" "+%Y-%m-%d") + :out + (string/trim-newline))] + (write-statement (str date " balance " account " " b " AUD")))) + (defn main [csv checking? & _args] (read-accounts beancount-file) @@ -372,4 +385,5 @@ (mapv write-transaction-to-file (drop-last (take-csv csv))) (mapv write-transaction-to-file-savings (drop-last (take-csv csv)))) (write-accounts beancount-file) + (assert-balance (last (take-csv csv)) checking?) (reset! new-accounts #{}))