This repository has been archived by the owner on Feb 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
services.js
67 lines (55 loc) · 2.09 KB
/
services.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const u = require('./utils.js');
const path = require('path');
const fs = require('fs');
// Class for accessing features from the 'All Online Services' header menu
module.exports = class Services {
constructor(session) {
this.session = session;
this.page = session.page;
}
async invoke_menu(page) {
// Download a single OFX for all accounts
await page.waitForSelector("a.button.viewAllOnlineServices")
// nav menu has display: none, so we need to request the document clicks 'All Online Services' inline
await page.evaluate(() => {
document.querySelector("a.button.viewAllOnlineServices").click();
});
}
async get_ofx_combined(out_path) {
// Barclays emits the download as data.ofx, unclear how to override this currently
let dest_basename = 'data.ofx'
let dest_filename = path.join(out_path, dest_basename)
// delete any existing dest_filename in out_path
try {
await fs.unlink(dest_filename)
} catch(err) {
}
await this.invoke_menu(this.page);
// click 'Export My Transaction data'
await this.page.waitForSelector("a#link_113")
await this.page.click("a#link_113")
// wait for download dialog
await this.page.waitForSelector("form[name='process-form']");
// click next in download dialog
await this.page.waitForSelector("input[type='submit']#next_step1");
await this.page.click("input[type='submit']#next_step1");
// wait for download button
let download_button = "input[type='submit']#data-download";
await this.page.waitForSelector(download_button);
await this.page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: out_path+'/'})
await this.page.click(download_button);
// delay for download (is there a more reliable way to detect a completed download response?)
await this.page.waitForTimeout(3000);
// verify existence of download file
try {
if (fs.existsSync(dest_filename)) {
console.log('OFX file exported as: ' + dest_filename)
}
else {
console.log('Error: ' + dest_filename + ' does not exist after attempting OFX download')
}
} catch(err) {
console.error('Error: ' + err)
}
}
}