-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathynab.go
More file actions
40 lines (38 loc) · 817 Bytes
/
ynab.go
File metadata and controls
40 lines (38 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/yremmet/ynab/client"
"github.com/yremmet/ynab/config"
"log"
"time"
)
func main() {
conf := config.ReadConfig()
fmt.Println(conf)
c := client.NewYNABClient(conf)
budgets, err := c.BudgetsService.GetBudgets()
if (err != nil){
handleError(err)
}
b := budgets.Data.Budgets[0]
fmt.Println(b)
accounts,err := c.AccountsService.GetAccounts(b)
if (err != nil){
handleError(err)
}
for _, a := range accounts.Data.Accounts {
if (a.Note != ""){
fmt.Printf("Exporting %s %s\n", a.Name, a.Note)
ts := Export(a.Note, a.Id)
err = c.TransactionsService.CreateTransactions(b, &ts)
if (err != nil){
handleError(err)
}
}
}
conf.SyncDate = time.Now()
config.WriteConfig(conf)
}
func handleError(err *client.ClientError) {
log.Fatal(err.Error())
}