add webserver for refresh hook
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
45
main.go
45
main.go
@@ -50,28 +50,33 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// Main program loop
|
||||
func main() {
|
||||
for {
|
||||
// Loop through each configured account provider and attempt to get the account balances, and update YNAB
|
||||
for _, p := range configuredProviders {
|
||||
balances, accountIDs, err := p.GetBalances()
|
||||
if err != nil {
|
||||
log.Printf("failed to get balances with provider '%s': %v", p.Name(), err)
|
||||
continue
|
||||
}
|
||||
if len(balances) != len(accountIDs) {
|
||||
log.Printf("'%s' provider data validation error: mismatched balance and accountID slice lengths - expected the same: balances length = %d, accountIDs length = %d", p.Name(), len(balances), len(accountIDs))
|
||||
continue
|
||||
}
|
||||
for i := range balances {
|
||||
err = ynabClient.SetAccountBalance(accountIDs[i], balances[i])
|
||||
if err != nil {
|
||||
log.Printf("failed to update ynab account '%s' balance: %v", accountIDs[i], err)
|
||||
}
|
||||
}
|
||||
}
|
||||
go webServer()
|
||||
|
||||
for { // Main program loop
|
||||
refreshData()
|
||||
log.Print("Sleeping for 6 hours...")
|
||||
time.Sleep(time.Hour * 6)
|
||||
}
|
||||
}
|
||||
|
||||
func refreshData() {
|
||||
// Loop through each configured account provider and attempt to get the account balances, and update YNAB
|
||||
for _, p := range configuredProviders {
|
||||
balances, accountIDs, err := p.GetBalances()
|
||||
if err != nil {
|
||||
log.Printf("failed to get balances with provider '%s': %v", p.Name(), err)
|
||||
continue
|
||||
}
|
||||
if len(balances) != len(accountIDs) {
|
||||
log.Printf("'%s' provider data validation error: mismatched balance and accountID slice lengths - expected the same: balances length = %d, accountIDs length = %d", p.Name(), len(balances), len(accountIDs))
|
||||
continue
|
||||
}
|
||||
for i := range balances {
|
||||
err = ynabClient.SetAccountBalance(accountIDs[i], balances[i])
|
||||
if err != nil {
|
||||
log.Printf("failed to update ynab account '%s' balance: %v", accountIDs[i], err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user