Skip to content

Instantly share code, notes, and snippets.

@andreyvital
Last active February 3, 2017 23:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreyvital/c20fa85346fd9079d17a9566d3c9c9d4 to your computer and use it in GitHub Desktop.
Save andreyvital/c20fa85346fd9079d17a9566d3c9c9d4 to your computer and use it in GitHub Desktop.
Total gasto no cartão Nubank https://nubank.com.br/. Uso: `nubank.sh <CPF> <senha>`
#!/usr/bin/env bash
set -e
JQ="jq --raw-output"
acquireTokenPayload=$(cat <<EOT
{
"client_id": "other.conta",
"client_secret": "yQPeLzoHuJzlMMSAjC-LgNUJdUecx8XO",
"grant_type": "password",
"login": "$1",
"password": "$2"
}
EOT)
acquireTokenPayload=$(echo -n $acquireTokenPayload)
response=$(
curl -s -H "Content-Type: application/json" -X POST -d "$acquireTokenPayload" \
https://prod-global-auth.nubank.com.br/api/token
)
eventsHref=$(echo $response |$JQ '._links.events.href')
accessToken=$(echo $response |$JQ '.access_token')
curl -s -H "Authorization: Bearer $accessToken" $eventsHref |\
$JQ '.events[] | select(.category == "transaction" and .amount > 0) | .amount' |\
xargs |\
sed 's/ /+/g' |\
bc |awk '{print "R$ " $1/100}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment