-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (61 loc) · 2.34 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const fs = require('fs');
const stripe = require('stripe')(process.env.API_KEY)
const puppeteer = require('puppeteer-extra')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())
const dateNow = Date.now()
async function getStripeBalance() {
await stripe.balance.retrieve((err, balance) => {
console.log('stripe', balance);
if (err) { return false }
balance.date = dateNow
fs.writeFile('docs/stripe.json', JSON.stringify(balance), 'utf8', (err) => {
if (err) console.log(err)
})
return true
})
}
getStripeBalance()
async function getBankBalance() {
const url = 'https://kunde.comdirect.de/lp/wt/login?execution=e2s1'
const browser = await puppeteer.launch({
headless: false
})
const page = await browser.newPage()
await page.goto(url)
await page.waitFor(2000)
let buttonCookie = ''
const buttonCookie1 = await page.$('#uc-btn-accept-banner')
const buttonCookie2 = await page.$('#privacy-init-wall-button-accept')
if (buttonCookie1) {
buttonCookie = buttonCookie1
}
if (buttonCookie2) {
buttonCookie = buttonCookie2
}
if (buttonCookie) { await buttonCookie.click() }
await page.waitFor(1000)
await page.type('#param1Input', process.env.BANK_1)
await page.waitFor(1000)
await page.type('#param3Input', process.env.BANK_2)
await page.waitForSelector('#loginAction')
const buttonSignin = await page.$('#loginAction')
await buttonSignin.click()
await page.waitFor(1000)
await page.waitForSelector('table')
const balanceWrapper = await page.$$('[data-label="Kontostand"]')
const balance = balanceWrapper[1]
const balanceValue = await page.evaluate(balance => balance.innerText, balance)
const balanceClean = balanceValue.split('€')[0].trim()
const balanceFloat = parseFloat(balanceClean.replace(/\./g, '').replace(/\,/g, '.'))
const balancesObject = { balances: { account: balanceFloat, date: dateNow } }
fs.writeFile('docs/bank.json', JSON.stringify(balancesObject), 'utf8', (err) => {
if (err) console.log(err)
})
await page.waitFor(2000)
await page.waitForSelector('#llLink')
const buttonLogout = await page.$('#llLink')
await buttonLogout.click()
await browser.close()
}
getBankBalance()