Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into ofx_combined
Browse files Browse the repository at this point in the history
  • Loading branch information
carpii authored May 27, 2021
2 parents 66f980f + 78cc423 commit 034c93d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ Options:
-h, --help output usage information
Commands:
list List all available accounts
get_ofx <out_path> Download individual .ofx files for each account, into out_path
list [options] List all available accounts
-j, --json Output account list in JSON format
get_ofx <out_path> Fetch .ofx files for all accounts into out_path
get_ofx_combined <out_path> Download a single .ofx file containing all account activity, into out_path
csv [options] Fetch .csv files for accounts
-p, --path <path> Export path. defaults to ./export
Expand Down
6 changes: 4 additions & 2 deletions account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const u = require('./utils.js');

// Class for dealing with the Barclays account page.
module.exports = class Account {
constructor(session, href, number) {
constructor(session, href, number, label, balance) {
this.session = session;
this.page = session.page;
this.number = number;
this.href = href;
this.number = number;
this.label = label;
this.balance = balance;
}

async select() {
Expand Down
9 changes: 8 additions & 1 deletion barclayscrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ program

program
.command('list')
.option('-j, --json', 'Output account list as a JSON object')
.description('List all available accounts')
.action(async options => {
var sess;
Expand All @@ -36,7 +37,13 @@ program

try {
const accounts = await sess.accounts();
console.table(accounts.map(acc => [acc.number, exportLabel(acc)]));
if (options.json) {
let account_list = accounts.map( function(acc) { return {'number': acc.number, 'alias': exportLabel(acc), 'name': acc.label, 'balance': acc.balance} });
console.log(JSON.stringify(account_list));
}
else {
console.table(accounts.map(acc => [acc.number, exportLabel(acc), acc.label, acc.balance]));
}
} catch (err) {
console.error(err);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "barclayscrape",
"version": "3.0.16",
"version": "3.0.17",
"description": "Programmatically manipulate Barclays online banking",
"main": "barclayscrape.js",
"bin": {
Expand Down
10 changes: 7 additions & 3 deletions session.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,25 @@ class Session {
return accounts.map(acc => {
return [
acc.querySelector('.my-account-link').getAttribute('href'),
acc.querySelector('.o-account').getAttribute('id').replace(/[^0-9]/g, '')
acc.querySelector('.o-account').getAttribute('id').replace(/[^0-9]/g, ''),
acc.querySelector('.my-account-link').textContent.trim(),
acc.querySelector('.o-account__balance-head') !== null ? acc.querySelector('.o-account__balance-head').textContent.trim().replace(/[£$]/g, '') : ''
]
});
});
let res = [];
accData.forEach(a => {
if (a[1] == '') {
if ((a[1] == '') || (a[3] == '')) {
return;
}

res.push(
new Account(
this,
a[0],
a[1]
a[1],
a[2],
a[3]
),
);
});
Expand Down

0 comments on commit 034c93d

Please sign in to comment.