~mendelmaleh/pfin

ref: c5c87e9e29a3cef13c618ae20c95d8b7a086e89f pfin/cmd/status/main.go -rw-r--r-- 851 bytes
c5c87e9eMendel E Rename util.TxString to FormatTx, refactor, move Fields to util 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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/parser/capitalone"
)

func main() {
	// parse config
	config, err := pfin.ParseConfig("")
	if err != nil {
		log.Fatal(err)
	}

	// parse accounts
	txns, err := util.ParseDir("capitalone", filepath.Join(config.Pfin.Root, "capitalone"))
	if err != nil {
		log.Fatal(err)
	}

	sort.SliceStable(txns, func(i, j int) bool {
		return txns[i].Date().Before(txns[j].Date())
	})

	// summary
	tw := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
	for _, tx := range txns {
		fmt.Fprintln(tw, pfin.TxString(tx, "\t"))
	}

	tw.Flush()

	// days since last transaction
	last := txns[len(txns)-1].Date()
	fmt.Println(int(time.Now().Sub(last).Hours()) / 24)
}