go run ./ cli rec to pull all from teller
cicd / ci (push) Failing after 18s
Details
cicd / ci (push) Failing after 18s
Details
parent
e0fa44eef7
commit
7a946b7604
|
|
@ -2,16 +2,22 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gogs.inhome.blapointe.com/ana-ledger/src/ana"
|
"gogs.inhome.blapointe.com/ana-ledger/src/ana"
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/src/bank"
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/src/bank/cache"
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/src/bank/teller"
|
||||||
"gogs.inhome.blapointe.com/ana-ledger/src/ledger"
|
"gogs.inhome.blapointe.com/ana-ledger/src/ledger"
|
||||||
|
|
||||||
"github.com/guptarohit/asciigraph"
|
"github.com/guptarohit/asciigraph"
|
||||||
|
|
@ -219,6 +225,60 @@ func Main() {
|
||||||
options = append(options, asciigraph.SeriesColors(seriesColors...))
|
options = append(options, asciigraph.SeriesColors(seriesColors...))
|
||||||
}
|
}
|
||||||
fmt.Println(asciigraph.PlotMany(points, options...))
|
fmt.Println(asciigraph.PlotMany(points, options...))
|
||||||
|
case "rec":
|
||||||
|
byDate := map[string]ledger.Deltas{}
|
||||||
|
for _, delta := range deltas {
|
||||||
|
delta := delta
|
||||||
|
byDate[delta.Date] = append(byDate[delta.Date], delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
|
||||||
|
defer can()
|
||||||
|
|
||||||
|
teller, err := teller.New()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
client := cache.New(teller)
|
||||||
|
|
||||||
|
accounts, err := client.Accounts(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
inDay := func(date string, transaction bank.Transaction) bool {
|
||||||
|
return slices.ContainsFunc(byDate[date], func(d ledger.Delta) bool {
|
||||||
|
return d.Value == transaction.Amount
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, acc := range accounts {
|
||||||
|
transactions, err := client.Transactions(ctx, acc)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, transaction := range transactions {
|
||||||
|
if inDay(transaction.Date, transaction) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err := "missing"
|
||||||
|
|
||||||
|
t, _ := time.ParseInLocation(transaction.Date, "2006-01-02", time.Local)
|
||||||
|
dayBefore := t.Add(-24 * time.Hour).Format("2006-01-02")
|
||||||
|
dayAfter := t.Add(-24 * time.Hour).Format("2006-01-02")
|
||||||
|
if inDay(dayBefore, transaction) || inDay(dayAfter, transaction) {
|
||||||
|
err = "1dayoff"
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := " "
|
||||||
|
if transaction.Status != "posted" {
|
||||||
|
prefix = "! "
|
||||||
|
}
|
||||||
|
fmt.Printf("[%s] %s $%7.2f %s%s (%s)\n", err, transaction.Date, transaction.Amount, prefix, transaction.Details.CounterParty.Name, transaction.Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
case "reg":
|
case "reg":
|
||||||
transactions := deltas.Transactions()
|
transactions := deltas.Transactions()
|
||||||
cumulative := make(ledger.Balances)
|
cumulative := make(ledger.Balances)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
cmd="bal"
|
cmd="bal"
|
||||||
case "$1" in
|
case "$1" in
|
||||||
bal|reg|gra|graph )
|
bal|reg|gra|graph|rec )
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ type Account struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
Amount string `json:"amount"`
|
Amount float64 `json:"amount,string"`
|
||||||
Details struct {
|
Details struct {
|
||||||
ProcessingStatus string `json:"processing_status"`
|
ProcessingStatus string `json:"processing_status"`
|
||||||
CounterParty struct {
|
CounterParty struct {
|
||||||
|
|
@ -25,6 +25,6 @@ type Transaction struct {
|
||||||
} `json:"details"`
|
} `json:"details"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
Type string `json:"fee"`
|
Type string `json:"type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue