Skip to content

Commit

Permalink
Print inquiries to stderr for stdin redirection, clarify date functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Jan 30, 2019
1 parent 0d5cbdb commit b8a7e8e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 41 deletions.
4 changes: 2 additions & 2 deletions scripts/balance/aws.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -80,8 +81,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/dkb.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -58,8 +59,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/fidor.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -56,8 +57,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/finvesto.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -59,8 +60,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/hypovereinsbank.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -57,8 +58,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/mbs.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -57,8 +58,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/paypal.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -88,8 +89,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
4 changes: 2 additions & 2 deletions scripts/balance/post.js
Expand Up @@ -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
: () => {}
Expand Down Expand Up @@ -49,8 +50,7 @@ async function getBalance (options = {}) {
}


inquirer
.prompt([
prompt([
{
type: 'input',
name: 'username',
Expand Down
8 changes: 4 additions & 4 deletions scripts/helpers.js
Expand Up @@ -3,8 +3,8 @@ module.exports = {
noteToAccount,
prettyFormat,
prettyPrint,
toDayMonthYear,
toDdotMdotYYYY,
toDDdotMMdotYYYY,
}


Expand All @@ -19,7 +19,7 @@ function prettyPrint (account, balance) {
}


function toDayMonthYear (date) {
function toDdotMdotYYYY (date) {
return [
date.getUTCDate(),
date.getUTCMonth() + 1,
Expand All @@ -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('.')
Expand Down
6 changes: 4 additions & 2 deletions scripts/transactions/dkb-visa.js
Expand Up @@ -15,6 +15,8 @@ const {
noteToAccount,
} = require('../helpers.js')

const prompt = inquirer.createPromptModule({ output: process.stderr })

nightmareDownloadManager(Nightmare)


Expand Down Expand Up @@ -200,8 +202,8 @@ async function getTransactions (options = {}) {


async function main () {
const answers = await inquirer
.prompt([
const answers = await
prompt([
{
type: 'input',
name: 'username',
Expand Down
28 changes: 17 additions & 11 deletions scripts/transactions/dkb.js
Expand Up @@ -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)


Expand Down Expand Up @@ -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,
}]
Expand All @@ -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)
Expand All @@ -105,7 +111,6 @@ async function downloadRange (options = {}) {
const {
nightmare,
filePathTemp,
// type = 'CSV-CAMT-Format',
startDate,
endDate,
} = options
Expand All @@ -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}`)
Expand Down Expand Up @@ -195,8 +201,8 @@ async function getTransactions (options = {}) {


async function main () {
const answers = await inquirer
.prompt([
const answers = await
prompt([
{
type: 'input',
name: 'username',
Expand All @@ -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'),
})
}
Expand Down
12 changes: 7 additions & 5 deletions scripts/transactions/hypovereinsbank.js
Expand Up @@ -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)


Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -184,8 +186,8 @@ async function getTransactions (options = {}) {


async function main () {
const answers = await inquirer
.prompt([
const answers = await
prompt([
{
type: 'input',
name: 'username',
Expand Down
6 changes: 3 additions & 3 deletions scripts/transactions/mbs.js
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8a7e8e

Please sign in to comment.