feat: multi-account Fio sync + switch QR default to 2502035405/2010
All checks were successful
Deploy to K8s / deploy (push) Successful in 24s
All checks were successful
Deploy to K8s / deploy (push) Successful in 24s
Add second Fio account (CZ0820100000002502035405 / 2502035405/2010). Both accounts are fetched on every sync run and combined before dedup, so the payments sheet accumulates transactions from either account. QR codes now default to the new account. Go: - config.go: hardcoded Accounts/LoadedAccount slice replaces scalar BankAccount + FioAPIToken; Config.BankAccount renamed QRAccount; per-account tokens via FIO_API_TOKEN_NEW / FIO_API_TOKEN_OLD - banksync.SyncToSheets: accepts []fio.Client, loops to combine txns - cmd/fuj/main.go: buildFioClients helper; both sync call sites updated - html_handler + build_adults/juniors: use Config.QRAccount - New TestSyncToSheets_MultiAccount covers cross-account dedup Python: - config.py: ACCOUNTS list + LOADED_ACCOUNTS (tokens from env) - fio_utils.py: fetch_transactions_for (per-account) + fetch_transactions_all (loops all accounts) - sync_fio_to_sheets.py: uses fetch_transactions_all Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,28 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Account describes a Fio bank account.
|
||||
type Account struct {
|
||||
IBAN string // e.g. "CZ0820100000002502035405"
|
||||
AcctNum string // bare account number, e.g. "2502035405"
|
||||
TokenEnv string // env var name holding the optional Fio API token
|
||||
Primary bool // true for the account QR codes default to
|
||||
}
|
||||
|
||||
// LoadedAccount is an Account with its token resolved from the environment.
|
||||
type LoadedAccount struct {
|
||||
Account
|
||||
Token string // value of os.Getenv(Account.TokenEnv); empty → transparent-scraper path
|
||||
}
|
||||
|
||||
// Accounts is the hardcoded list of Fio bank accounts to sync from.
|
||||
// The first entry with Primary=true is used for QR codes.
|
||||
// Tokens are loaded at runtime from each account's TokenEnv.
|
||||
var Accounts = []Account{
|
||||
{IBAN: "CZ0820100000002502035405", AcctNum: "2502035405", TokenEnv: "FIO_API_TOKEN_NEW", Primary: true},
|
||||
{IBAN: "CZ8520100000002800359168", AcctNum: "2800359168", TokenEnv: "FIO_API_TOKEN_OLD"},
|
||||
}
|
||||
|
||||
// Google Sheets IDs — change in code if sheets change (not from env).
|
||||
const (
|
||||
AttendanceSheetID = "1E2e_gT_K5AwSRCDLDTa2UetZTkHmBOcz0kFbBUNUNBA"
|
||||
@@ -34,28 +56,36 @@ var CacheSheetMap = map[string]string{
|
||||
// Mirrors scripts/config.py.
|
||||
type Config struct {
|
||||
CredentialsPath string
|
||||
BankAccount string
|
||||
QRAccount string // IBAN of the primary account used for QR codes
|
||||
LoadedAccounts []LoadedAccount // all accounts to sync, tokens resolved from env
|
||||
CacheDir string
|
||||
CacheTTL time.Duration
|
||||
CacheAPICheckTTL time.Duration
|
||||
DriveTimeout time.Duration
|
||||
LogLevel string
|
||||
FioAPIToken string
|
||||
ServerAddr string
|
||||
}
|
||||
|
||||
// Load reads configuration from the environment, applying defaults that
|
||||
// match the Python side.
|
||||
func Load() Config {
|
||||
loaded := make([]LoadedAccount, len(Accounts))
|
||||
var qrAccount string
|
||||
for i, a := range Accounts {
|
||||
loaded[i] = LoadedAccount{Account: a, Token: os.Getenv(a.TokenEnv)}
|
||||
if a.Primary {
|
||||
qrAccount = a.IBAN
|
||||
}
|
||||
}
|
||||
return Config{
|
||||
CredentialsPath: env("CREDENTIALS_PATH", ".secret/fuj-management-bot-credentials.json"),
|
||||
BankAccount: env("BANK_ACCOUNT", "CZ8520100000002800359168"),
|
||||
QRAccount: qrAccount,
|
||||
LoadedAccounts: loaded,
|
||||
CacheDir: env("CACHE_DIR", "tmp/go"),
|
||||
CacheTTL: envDuration("CACHE_TTL_SECONDS", 300),
|
||||
CacheAPICheckTTL: envDuration("CACHE_API_CHECK_TTL_SECONDS", 300),
|
||||
DriveTimeout: envDuration("DRIVE_TIMEOUT_SECONDS", 10),
|
||||
LogLevel: env("LOG_LEVEL", "INFO"),
|
||||
FioAPIToken: env("FIO_API_TOKEN", ""),
|
||||
ServerAddr: env("SERVER_ADDR", ":8080"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user