-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
55 lines (44 loc) · 1.6 KB
/
index.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
var fs = require('fs');
var system = require('system');
var casper = require('casper').create({
viewportSize: { width: 1280, height: 800 },
verbose: false,
logLevel: "debug",
waitTimeout: 10 * 1000
});
var ynabUsername = system.env.C2Y_YNAB_USERNAME;
var ynabPassword = system.env.C2Y_YNAB_PASSWORD;
var bank = system.env.C2Y_BANK || 'nl/ing';
casper.echo('Fetching transactions from ' + bank)
require('banks/' + bank)(casper);
casper.thenOpen('https://app.youneedabudget.com/users/login');
casper.waitForSelector('.login-username', function() {
casper.sendKeys('.login-username', ynabUsername);
casper.sendKeys('.login-password', ynabPassword);
this.click('.users-form button.button-primary');
});
casper.waitForSelector(".budget-header-totals-amount", function() {
this.echo("Logged in to YNAB");
this.click('.nav-account-row');
});
casper.waitForSelector(".accounts-toolbar-file-import-transactions", function() {
this.click('.accounts-toolbar-file-import-transactions');
});
casper.waitForSelector(".modal-import-choose-file", function() {
this.echo("Uploading file");
this.page.uploadFile('input[type="file"]', 'ynab.csv');
});
casper.waitForSelector(".modal-import-review", function() {
this.click('.modal-import-review button.button-primary');
});
casper.waitForText("Import Successful", function() {
this.echo("Import Successful");
this.click('.modal-import-successful button.button-primary');
});
casper.waitWhileSelector(".import-preview-select-date .ynab-select-option", function() {
this.echo("Finished!");
});
casper.run(function() {
this.echo("Closing...");
this.exit(0);
});