~mendelmaleh/pfin

894d1bab7e1630e9c091f8f1152c73065cc37b96 — Mendel E 2 months ago c5c87e9 v0.4
Update cmd/status
1 files changed, 17 insertions(+), 20 deletions(-)

M cmd/status/main.go
M cmd/status/main.go => cmd/status/main.go +17 -20
@@ 3,16 3,13 @@ package main
import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"sort"
	"text/tabwriter"
	"time"

	"git.sr.ht/~mendelmaleh/pfin"
	"git.sr.ht/~mendelmaleh/pfin/parser/util"
	"git.sr.ht/~mendelmaleh/pfin/util"

	_ "git.sr.ht/~mendelmaleh/pfin/parser/capitalone"
	_ "git.sr.ht/~mendelmaleh/pfin/parser/all"
)

func main() {


@@ 23,24 20,24 @@ func main() {
	}

	// parse accounts
	txns, err := util.ParseDir("capitalone", filepath.Join(config.Pfin.Root, "capitalone"))
	if err != nil {
		log.Fatal(err)
	}
	txns := make(map[string][]pfin.Transaction, len(config.Account))

	sort.SliceStable(txns, func(i, j int) bool {
		return txns[i].Date().Before(txns[j].Date())
	})
	for name, acc := range config.Account {
		tx, err := util.ParseDir(acc, config.Pfin.Root)
		if err != nil {
			log.Fatal(err)
		}

	// summary
	tw := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
	for _, tx := range txns {
		fmt.Fprintln(tw, pfin.TxString(tx, "\t"))
	}
		sort.SliceStable(tx, func(i, j int) bool {
			return tx[i].Date().Before(tx[j].Date())
		})

	tw.Flush()
		txns[name] = tx
	}

	// days since last transaction
	last := txns[len(txns)-1].Date()
	fmt.Println(int(time.Now().Sub(last).Hours()) / 24)
	for name, tx := range txns {
		last := tx[len(tx)-1].Date()
		fmt.Printf("%s: %d\n", name, int(time.Now().Sub(last).Hours())/24)
	}
}