Update to latest upstream API changes

parent 7f0adc67
Pipeline #921 failed with stages
in 42 seconds
......@@ -92,15 +92,22 @@ func executeFetch() error {
err = user.FetchAccounts(aq)
if err != nil {
fmt.Printf("unable to list accounts: %v", err)
fmt.Printf("unable to fetch accounts: %v", err)
// panic(err)
}
accountCollection, err := aq.Accounts()
if err != nil {
fmt.Printf("unable to list accounts: %v", err)
// panic(err)
}
for _, account := range accountCollection.Accounts {
latestPayment, err := context.LatestPaymentFromSource("hbci")
if err != nil {
// panic(err)
}
for _, account := range accountCollection {
fmt.Printf("%v", account)
transactions, err := aq.AllTransactions(&account)
if err != nil {
......@@ -109,17 +116,28 @@ func executeFetch() error {
for _, transaction := range transactions {
spew.Dump(transaction)
if time.Since(transaction.ValutaDate) <= time.Hour*24 {
fmt.Println("Skipping, too new")
continue
}
if !transaction.ValutaDate.After(latestPayment.CreatedAt) {
fmt.Println("Skipping, known")
continue
}
valuei, _ := big.NewFloat(float64(transaction.Total) * 100.0).Int64()
t := db.Transaction{
BudgetID: 6,
Amount: valuei,
t := db.Payment{
BudgetID: 1,
CreatedAt: transaction.ValutaDate,
RemotePurpose: transaction.Purpose,
Amount: valuei,
Currency: "EUR",
Purpose: transaction.Purpose,
RemoteAccount: transaction.RemoteAccountNumber,
RemoteBankID: transaction.RemoteBankCode,
RemoteName: transaction.RemoteName,
Source: "hbci",
}
//spew.Dump(t)
err = t.Save(context)
if err != nil {
panic(err)
......
......@@ -13,6 +13,8 @@ import (
)
var (
configFile, logLevelStr string
// RootCmd is the core command used for cli-arg parsing
RootCmd = &cobra.Command{
Use: "hbci",
......@@ -25,10 +27,12 @@ var (
)
func main() {
var configFile, logLevelStr string
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "config.json", "use this config file (JSON format)")
RootCmd.PersistentFlags().StringVarP(&logLevelStr, "loglevel", "l", "info", "log level")
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
}
func initConfig() {
logLevel, err := log.ParseLevel(logLevelStr)
if err != nil {
log.Fatal(err)
......@@ -44,8 +48,10 @@ func main() {
db.SetupPostgres(config.Settings.Connections.PostgreSQL)
mq.SetupAMQP(config.Settings.Connections.AMQP)
}
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "config.json", "use this config file (JSON format)")
RootCmd.PersistentFlags().StringVarP(&logLevelStr, "loglevel", "l", "info", "log level")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment