From b8a7e8e1d3d027ad0351ffab4282e5f33c2488aa Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Wed, 30 Jan 2019 15:11:57 +0000 Subject: [PATCH] Print inquiries to stderr for stdin redirection, clarify date functions --- scripts/balance/aws.js | 4 ++-- scripts/balance/dkb.js | 4 ++-- scripts/balance/fidor.js | 4 ++-- scripts/balance/finvesto.js | 4 ++-- scripts/balance/hypovereinsbank.js | 4 ++-- scripts/balance/mbs.js | 4 ++-- scripts/balance/paypal.js | 4 ++-- scripts/balance/post.js | 4 ++-- scripts/helpers.js | 8 +++---- scripts/transactions/dkb-visa.js | 6 ++++-- scripts/transactions/dkb.js | 28 +++++++++++++++---------- scripts/transactions/hypovereinsbank.js | 12 ++++++----- scripts/transactions/mbs.js | 6 +++--- 13 files changed, 51 insertions(+), 41 deletions(-) diff --git a/scripts/balance/aws.js b/scripts/balance/aws.js index 6522764..6249cd0 100644 --- a/scripts/balance/aws.js +++ b/scripts/balance/aws.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -80,8 +81,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/dkb.js b/scripts/balance/dkb.js index 8de8fa8..2793ee9 100644 --- a/scripts/balance/dkb.js +++ b/scripts/balance/dkb.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -58,8 +59,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/fidor.js b/scripts/balance/fidor.js index 59d7b0f..70283bd 100644 --- a/scripts/balance/fidor.js +++ b/scripts/balance/fidor.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -56,8 +57,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/finvesto.js b/scripts/balance/finvesto.js index 1da0b21..381d9bf 100644 --- a/scripts/balance/finvesto.js +++ b/scripts/balance/finvesto.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -59,8 +60,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/hypovereinsbank.js b/scripts/balance/hypovereinsbank.js index 0c98caa..c10dc5a 100644 --- a/scripts/balance/hypovereinsbank.js +++ b/scripts/balance/hypovereinsbank.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -57,8 +58,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/mbs.js b/scripts/balance/mbs.js index 0ba2f11..d4fd035 100644 --- a/scripts/balance/mbs.js +++ b/scripts/balance/mbs.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -57,8 +58,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/paypal.js b/scripts/balance/paypal.js index 64c5c6e..6d34165 100644 --- a/scripts/balance/paypal.js +++ b/scripts/balance/paypal.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -88,8 +89,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/balance/post.js b/scripts/balance/post.js index e81c514..10758c4 100644 --- a/scripts/balance/post.js +++ b/scripts/balance/post.js @@ -5,6 +5,7 @@ const Nightmare = require('nightmare') const {prettyPrint} = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) const log = process.env.NODE_DEBUG ? console.warn : () => {} @@ -49,8 +50,7 @@ async function getBalance (options = {}) { } -inquirer - .prompt([ +prompt([ { type: 'input', name: 'username', diff --git a/scripts/helpers.js b/scripts/helpers.js index 2fc65e1..b25ef63 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -3,8 +3,8 @@ module.exports = { noteToAccount, prettyFormat, prettyPrint, - toDayMonthYear, toDdotMdotYYYY, + toDDdotMMdotYYYY, } @@ -19,7 +19,7 @@ function prettyPrint (account, balance) { } -function toDayMonthYear (date) { +function toDdotMdotYYYY (date) { return [ date.getUTCDate(), date.getUTCMonth() + 1, @@ -28,9 +28,9 @@ function toDayMonthYear (date) { } -function toDdotMdotYYYY (date) { +function toDDdotMMdotYYYY (date) { return [ - date.getUTCDate(), + ('0' + String(date.getUTCDate())).slice(-2), ('0' + String(date.getUTCMonth() + 1)).slice(-2), date.getUTCFullYear(), ].join('.') diff --git a/scripts/transactions/dkb-visa.js b/scripts/transactions/dkb-visa.js index 5a5884e..e442090 100644 --- a/scripts/transactions/dkb-visa.js +++ b/scripts/transactions/dkb-visa.js @@ -15,6 +15,8 @@ const { noteToAccount, } = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) + nightmareDownloadManager(Nightmare) @@ -200,8 +202,8 @@ async function getTransactions (options = {}) { async function main () { - const answers = await inquirer - .prompt([ + const answers = await + prompt([ { type: 'input', name: 'username', diff --git a/scripts/transactions/dkb.js b/scripts/transactions/dkb.js index 91498de..1953efc 100644 --- a/scripts/transactions/dkb.js +++ b/scripts/transactions/dkb.js @@ -10,11 +10,13 @@ const converter = require('converter') const inquirer = require('inquirer') const { - toDayMonthYear, + toDDdotMMdotYYYY, keysToEnglish, noteToAccount, } = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) + nightmareDownloadManager(Nightmare) @@ -64,15 +66,15 @@ function normalizeAndPrint (filePathTemp) { const transfersObj = transaction.amount.startsWith('-') ? { transfers: [{ - from: 'dkb:visa', - to: noteToAccount(transaction.note), + from: 'dkb:giro', + to: noteToAccount(note), amount: amount.slice(1), }] } : { transfers: [{ - from: noteToAccount(transaction.note), - to: 'dkb:visa', + from: noteToAccount(note), + to: 'dkb:giro', // TODO: Remove when github.com/adius/csvnorm/issues/1 is solved amount: transaction.amount === '0,00' ? '0 €' : amount, }] @@ -83,6 +85,10 @@ function normalizeAndPrint (filePathTemp) { return JSON.parse(JSON.stringify(newTransaction, rmEmptyString)) }) + .sort((a, b) => + // Oldest first + String(a.utc).localeCompare(String(b.utc), 'en') + ) const yamlString = yaml .dump(transactions) @@ -105,7 +111,6 @@ async function downloadRange (options = {}) { const { nightmare, filePathTemp, - // type = 'CSV-CAMT-Format', startDate, endDate, } = options @@ -130,12 +135,13 @@ async function downloadRange (options = {}) { await nightmare .insert(startInputSelector, '') - .insert(startInputSelector, toDayMonthYear(startDate)) + .insert(startInputSelector, toDDdotMMdotYYYY(startDate)) .insert(endInputSelector, '') - .insert(endInputSelector, toDayMonthYear(endDate)) + .insert(endInputSelector, toDDdotMMdotYYYY(endDate)) .click('#searchbutton') + .refresh() // Necessary to avoid race condition log(`Download CSV file to ${filePathTemp}`) @@ -195,8 +201,8 @@ async function getTransactions (options = {}) { async function main () { - const answers = await inquirer - .prompt([ + const answers = await + prompt([ { type: 'input', name: 'username', @@ -213,7 +219,7 @@ async function main () { username: answers.username, password: answers.password, shallShowBrowser: true, - numberOfDays: 300, + numberOfDays: 1095, // startDate: new Date('2016-01-01'), }) } diff --git a/scripts/transactions/hypovereinsbank.js b/scripts/transactions/hypovereinsbank.js index 275b1aa..7150e7a 100644 --- a/scripts/transactions/hypovereinsbank.js +++ b/scripts/transactions/hypovereinsbank.js @@ -10,11 +10,13 @@ const converter = require('converter') const inquirer = require('inquirer') const { - toDayMonthYear, + toDdotMdotYYYY, keysToEnglish, noteToAccount, } = require('../helpers.js') +const prompt = inquirer.createPromptModule({ output: process.stderr }) + nightmareDownloadManager(Nightmare) @@ -123,10 +125,10 @@ async function downloadRange (options = {}) { ) await nightmare .insert(startInputSelector, '') - .insert(startInputSelector, toDayMonthYear(startDate)) + .insert(startInputSelector, toDdotMdotYYYY(startDate)) .insert(endInputSelector, '') - .insert(endInputSelector, toDayMonthYear(endDate)) + .insert(endInputSelector, toDdotMdotYYYY(endDate)) .click('#j_id_12') @@ -184,8 +186,8 @@ async function getTransactions (options = {}) { async function main () { - const answers = await inquirer - .prompt([ + const answers = await + prompt([ { type: 'input', name: 'username', diff --git a/scripts/transactions/mbs.js b/scripts/transactions/mbs.js index 48d9b98..602a439 100644 --- a/scripts/transactions/mbs.js +++ b/scripts/transactions/mbs.js @@ -8,7 +8,7 @@ const tempy = require('tempy') const csvnorm = require('csvnorm') const converter = require('converter') -const {toDayMonthYear} = require('../helpers.js') +const {toDdotMdotYYYY} = require('../helpers.js') nightmareDownloadManager(Nightmare) @@ -123,10 +123,10 @@ async function downloadRange (options = {}) { ) await nightmare .insert(startInputSelector, '') - .insert(startInputSelector, toDayMonthYear(startDate)) + .insert(startInputSelector, toDdotMdotYYYY(startDate)) .insert(endInputSelector, '') - .insert(endInputSelector, toDayMonthYear(endDate)) + .insert(endInputSelector, toDdotMdotYYYY(endDate)) .click('.bcontinue input[type=submit]') .refresh() // Necessary to update the list