Skip to content

Commit

Permalink
transactions: watch: use a future date to fetch latest transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
  • Loading branch information
wantguns committed Oct 17, 2023
1 parent 1a611f0 commit 9807892
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
TransactionsCmd.Flags().StringP("since", "s", yesterday, "fetch transactions since in this format: YYYY-MM-DD")
TransactionsCmd.Flags().BoolP("db", "d", false, "Save the results in a sqlite db")
TransactionsCmd.Flags().StringP("db-path", "D", "db.sqlite", "Sets path for the database")
TransactionsCmd.Flags().Bool("no-plaintext", false, "Do not return plaintext output")
TransactionsCmd.Flags().StringP("watch", "w", "", "Set an internal cron job to trigger this command. You can use non-standard cron expressions like '@every 6h'. This will disable plaintext mode, so add a '-d' flag if you want to write to db")
}

Expand All @@ -58,7 +59,7 @@ func setupTransactionsCmdHandler(cmd *cobra.Command, args []string) {
c.AddFunc(watch, func() {

// Update the `till` and `plaintext` value
now := time.Now().Format(time.DateOnly)
now := time.Now().AddDate(0, 0, 1).Format(time.DateOnly)
oldArgs := os.Args[1:]
log.Debug().Msgf("Old arguments %+v", oldArgs)
cmd.SetArgs(append(oldArgs, fmt.Sprintf("--till=%s", now), "--no-plaintext"))
Expand Down Expand Up @@ -152,7 +153,7 @@ func transactionsCmdHandler(cmd *cobra.Command, args []string) {
}

// If plaintext is enabled
if noPlaintext := cmd.Flags().Lookup("no-plaintext"); noPlaintext != nil {
if noPlaintext, _ := cmd.Flags().GetBool("no-plaintext"); noPlaintext {
printTransactions(t[i])
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ automatically logged out on your Phone's app**
$ unfold transactions -s 2023-09-20 --db -w '@every 20s'
12:19AM INF Cron job set for fetching transactions, going into daemon mode
12:19AM INF Fetched transactions till 2023-10-17
12:20AM INF Fetched transactions till 2023-10-16
12:20AM INF Fetched transactions till 2023-10-17
```
c. For a complete glossary of available options:
d. For a complete glossary of available options:
```
$ unfold transactions -h
Prints the transactions from all of your accounts (default period: 1 month)
Expand Down

0 comments on commit 9807892

Please sign in to comment.