Files: dbca04e9f509c2791256e4f5b36a2e2c53f26e9f / index.js
1273 bytesRaw
1 | const numeral = require('numeral') |
2 | const Starling = require('starling-developer-sdk') |
3 | const moment = require('moment') |
4 | |
5 | const client = new Starling({ |
6 | accessToken: process.env.STARLING_TOKEN |
7 | }) |
8 | |
9 | const main = async () => { |
10 | const balance = await client.getBalance() |
11 | const account = await client.getAccount() |
12 | |
13 | console.log(`${account.data.createdAt.substring(0, 10)} open Assets:GB:Starling:Checking ${account.data.currency}\n`) |
14 | |
15 | const transactions = await client.getTransactions(process.env.STARLING_TOKEN, account.data.createdAt.substring(0, 10), '2018-10-22') |
16 | |
17 | transactions.data._embedded.transactions.reverse().forEach(t => { |
18 | console.log([ |
19 | `${t.created.substring(0, 10)} * "${t.narrative}"`, |
20 | ` ${t.direction === 'OUTBOUND' ? 'Assets:GB:Starling:Checking' : 'Income:Unknown'} ${numeral(t.direction === 'OUTBOUND' ? t.amount : -t.amount).format('0.00')} ${t.currency}`, |
21 | ` ${t.direction === 'OUTBOUND' ? 'Expenses:Unknown' : 'Assets:GB:Starling:Checking'} ${numeral(t.direction === 'OUTBOUND' ? -t.amount : t.amount).format('0.00')} GBP` |
22 | ].join('\n') + '\n') |
23 | }) |
24 | |
25 | console.log(`${moment().format('YYYY-MM-DD')} balance Assets:GB:Starling:Checking ${balance.data.amount} ${account.data.currency}\n`) |
26 | } |
27 | |
28 | main().catch(console.error) |
29 |
Built with git-ssb-web