UNPKG

n26-puppeteer-scraper

Version:

n26 scraper: a tool to download account informations and transactions archive

37 lines (31 loc) 1.33 kB
const n26getBankStatements = require('../../lib/n26-get-bank-statements') const extractCookies = require('../../lib/extract-cookies') const n26login = require('../../lib/n26-login') const download = require('download') const fs = require('fs') const path = require('path') const debug = require('debug') const pRetry = require('p-retry') const log = debug('n26:bin:statements:download') exports.command = 'download' exports.desc = 'download bank statements' exports.builder = {} exports.handler = async (argv) => { debug.enable('n26:*') const { page } = await n26login(argv, { loadMembership: false }) const statements = await n26getBankStatements(page) const cookies = await extractCookies(page) fs.mkdirSync(path.resolve(process.cwd(), 'statements'), { recursive: true }) for (const st of statements) { await pRetry(async () => { await new Promise((resolve) => setTimeout(resolve, 2000)) log(`- downloading ${st.date}\t${st.link}`) const statementsPath = path.resolve(process.cwd(), 'statements') const pdfPath = path.resolve(statementsPath, `${st.date}.pdf`) await download(st.link, statementsPath, { headers: { Cookie: cookies } }) await new Promise((resolve) => setTimeout(resolve, 5000)) log(`saved ${pdfPath}`) }, { retries: 3 }) } process.exit(0) }