Deploy to K8s / deploy (push) Successful in 20s
Go (go/) becomes the primary implementation. The original Python version moves to legacy/ and is kept runnable; new features are still built in both (see the Dual implementation rule in CLAUDE.md). - git mv app.py, scripts/, templates/, tests/, pyproject.toml, uv.lock and build/ into legacy/ - Makefile: Python targets point at legacy/, venv in legacy/.venv, CREDENTIALS_PATH exported for the root .secret/ file - CI and make image build the Python image with legacy/ as context; the Makefile is no longer copied into the image - legacy/.dockerignore moved to the context root so it takes effect - CLAUDE.md, docs/README.md, Go comments, fixture README, capture script and VS Code launch config updated to the new layout Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
// Package synch ports the bank-sync deduplication helper from
|
|
// legacy/scripts/sync_fio_to_sheets.py.
|
|
package synch
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"math"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Transaction is the projection of a Fio transaction that participates
|
|
// in the Sync ID hash. Other fields (ks, ss, sender_account, …) are
|
|
// intentionally excluded — they are not part of the Python hash.
|
|
//
|
|
// Currency: leave "" to inherit the Python default of "CZK" (matches
|
|
// the HTML scraper path which omits the key entirely).
|
|
type Transaction struct {
|
|
Date string
|
|
Amount float64
|
|
Currency string
|
|
Sender string
|
|
VS string
|
|
Message string
|
|
BankID string
|
|
}
|
|
|
|
// GenerateSyncID returns the lowercase SHA-256 hex digest of
|
|
// "date|amount|currency|sender|vs|message|bank_id" (lower-cased), used
|
|
// as the dedup key in column K of the payments sheet.
|
|
//
|
|
// Byte-stable with legacy/scripts/sync_fio_to_sheets.py generate_sync_id.
|
|
func GenerateSyncID(tx Transaction) string {
|
|
currency := tx.Currency
|
|
if currency == "" {
|
|
currency = "CZK"
|
|
}
|
|
raw := strings.ToLower(strings.Join([]string{
|
|
tx.Date,
|
|
formatAmount(tx.Amount),
|
|
currency,
|
|
tx.Sender,
|
|
tx.VS,
|
|
tx.Message,
|
|
tx.BankID,
|
|
}, "|"))
|
|
sum := sha256.Sum256([]byte(raw))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|
|
|
|
// formatAmount mimics Python's str(float) for Fio transaction amounts.
|
|
// Python uses decimal notation for abs(f) in [1e-4, 1e16) and scientific
|
|
// notation outside that range, always adding ".0" to whole-valued decimals.
|
|
func formatAmount(f float64) string {
|
|
abs := math.Abs(f)
|
|
if abs != 0 && (abs < 1e-4 || abs >= 1e16) {
|
|
return strconv.FormatFloat(f, 'e', -1, 64)
|
|
}
|
|
s := strconv.FormatFloat(f, 'f', -1, 64)
|
|
if !strings.ContainsRune(s, '.') {
|
|
s += ".0"
|
|
}
|
|
return s
|
|
}
|