All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vvcephei.scalaofx.cli.CLI.scala Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
package org.vvcephei.scalaofx.cli

import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.datatype.joda.JodaModule
import scala.xml.PrettyPrinter
import com.beust.jcommander.JCommander
import org.vvcephei.scalaofx.client.{SourceClient, BankClient}
import org.vvcephei.scalaofx.lib.parser.OfxMessage
import org.vvcephei.scalaofx.lib.model.response.{BankStatementResponse, BankStatement, BankAccountInfo}
import scala.io.Source

object CLI {
  private val mapper = new ObjectMapper() with ScalaObjectMapper {
    registerModule(DefaultScalaModule)
    registerModule(new JodaModule)
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
  } writerWithDefaultPrettyPrinter()
  private val pr = new PrettyPrinter(80, 2)

  def main(args: Array[String]): Unit = {
    new JCommander(Options, args: _*)

    if (!Options.ofxFile.isEmpty) {
      val statements = SourceClient.bankStatements(Source.fromFile(Options.ofxFile))
      println(statements)
      printStatements(statements.statements)
    }

    for ((login, accounts) <- Options.loginToAccounts) {
      val bc = BankClient(login.user, login.bank, debug = Options.verbose)

      println()
      println("========================================")
      println(accounts)
      println(login)

      println()
      println(" sign on")
      val signon = bc.signOn()
      println(pr format signon.ofx)

      println()
      println(" profile")
      val profile: OfxMessage = bc.profile()
      println(pr format profile.ofx)

      println()
      println(" acctinfo")
      val info: Seq[BankAccountInfo] = bc.accountInfo()
      println(mapper writeValueAsString info)

      println()
      println(" statement")
      val statements: BankStatementResponse = bc.bankStatements(accounts, Options.start)
      println(mapper writeValueAsString statements.errors)
      println(mapper writeValueAsString statements.statements)

      printStatements(statements.statements)
    }
  }

  def printStatements(statements: Seq[BankStatement]) {
    for (statement <- statements) {
      println(s"Balance: ${statement.availableBalance}")
      for (transaction <- statement.transactions) {
        println(s"date: ${transaction.posted}, type: ${transaction.`type`}, amount: ${transaction.amount}, payee: ${transaction.name}, memo: ${transaction.memo}")
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy