~mendelmaleh/pfin

ref: parallel pfin/cmd/status/main.go -rw-r--r-- 777 bytes
95ffe938Mendel E Parallelize directory parsing 7 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
package main

import (
	"fmt"
	"log"
	"sort"
	"time"

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

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

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

	// parse accounts
	txns := make(map[string][]pfin.Transaction, len(config.Account))

	for name, acc := range config.Account {
		tx, err := util.ParseDir(acc, config.Pfin.Root)
		if err != nil {
			log.Fatal(err)
		}

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

		txns[name] = tx
	}

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