Skip to content

Instantly share code, notes, and snippets.

@guilhermedecampo
Last active June 21, 2020 19:56
Show Gist options
  • Save guilhermedecampo/916025880650643469730cd0af8decf3 to your computer and use it in GitHub Desktop.
Save guilhermedecampo/916025880650643469730cd0af8decf3 to your computer and use it in GitHub Desktop.
A better Nubank csv web downloader using chrome dev tools

Nicer CSV download of nubank data

Function

function downloadNubankCSV({ date }) {
  const transactions = angular.element(document.body).injector().get('Bills').all.map(bill => bill.more.line_items).flat()
  const regExp = new RegExp(date, 'g')
  const csv = transactions
    // filtering wanted/unwanted datapoints
    .filter(info => info.post_date.match(regExp) && !info.title.match(/Pagamento recebido/g))
.sort((a, b) =>Number(a.post_date.slice(-2)) - Number(b.post_date.slice(-2)))
    .map(info =>
      [
        info.post_date,
        info.title,
        (info.description || ''),
        (info.amount || 0) / 100,
      ].join(','),
    )
    .join('\n')
  const element = document.createElement('a')
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(csv))
  element.setAttribute('download', `${date}-nubank.csv`)

  element.style.display = 'none'
  document.body.appendChild(element)

  element.click()

  document.body.removeChild(element)
}

Usage

  1. Access your nubank account in webmode
  2. Open chrome dev tool on network tab
  3. Run the fn: downloadNubankCSV({ date: '2019-10' })
  4. Profits

Futurah

Convert this into a chrome extension that has a select input so you can download Year/Month you would like

To be FIXED

  • Check corner cases
  • Add agnostic way to filter (fobiddenList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment