All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
Wires slog.SetDefault to honour LOG_LEVEL in all CLI commands and adds debug logs on the Fio fetch path so a silent "fetched 0 transaction(s)" can be diagnosed without code changes: - fio.New: which client variant (api/transparent) was selected - apiClient: GET URL (token redacted as ****), HTTP status, body bytes, parsed transaction count - transparentClient: GET URL, HTTP status, body bytes, plus parser stats (raw rows from second table, kept, dropped_bad_date, dropped_nonpositive_amount) Also suppresses the --print-fio-table block when zero transactions were fetched, so the bare header no longer prints under that condition. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
// Package fio fetches Fio bank transactions via the JSON API or the
|
|
// transparent-page HTML scraper, behind a common Client interface.
|
|
package fio
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Transaction is one incoming bank payment. Fields absent from the HTML scraper
|
|
// (BankID, Currency, UserID, SenderAccount) are empty strings on that path.
|
|
type Transaction struct {
|
|
Date string
|
|
Amount float64
|
|
Sender string
|
|
Message string
|
|
VS string
|
|
KS string
|
|
SS string
|
|
UserID string // column7; empty on HTML path
|
|
SenderAccount string // column2; empty on HTML path
|
|
BankID string // column22; empty on HTML path
|
|
Currency string // column14; empty on HTML path (assume CZK)
|
|
}
|
|
|
|
// Client fetches transactions for a date window.
|
|
type Client interface {
|
|
FetchTransactions(ctx context.Context, from, to time.Time) ([]Transaction, error)
|
|
}
|
|
|
|
// New returns an apiClient when token is non-empty, otherwise a transparentClient.
|
|
// hc may be nil, in which case http.DefaultClient is used.
|
|
func New(token, accountNum string, hc httpDoer) Client {
|
|
if hc == nil {
|
|
hc = http.DefaultClient
|
|
}
|
|
if token != "" {
|
|
slog.Debug("fio: client selected", "type", "api")
|
|
return &apiClient{token: token, hc: hc}
|
|
}
|
|
slog.Debug("fio: client selected", "type", "transparent", "account_num", accountNum)
|
|
return &transparentClient{accountNum: accountNum, hc: hc}
|
|
}
|