Skip to content

Instantly share code, notes, and snippets.

@danilopopeye
Last active July 3, 2016 21:23
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 danilopopeye/a41f5fd7dc549fab2833 to your computer and use it in GitHub Desktop.
Save danilopopeye/a41f5fd7dc549fab2833 to your computer and use it in GitHub Desktop.
Sodexo2ynab: exporte as transações do seu cartão Sodexo para CSV no formato do YNAB

Sodexo2ynab

Exporte as transações do seu cartão Sodexo para CSV no formato do You Need A Budget.

Tutorial

  1. Crie um bookmarklet com o snipet que está no final da página
  2. Acesse o site: https://sodexosaldocartao.com.br e faça o login
  3. Clique no bookmarklet na barra de favoritos
  4. O download do arquivo sodexo_{últimos 4 digitos}.csv deve ter sido iniciado
  5. Profit! 🌟
javascript:(function(d,u,s){s=d.createElement('script');s.type='text/javascript';s.charset='utf-8';s.src=u;d.body.appendChild(s);})(document,'https://rawgit.com/danilopopeye/a41f5fd7dc549fab2833/raw/sodexo.js')
(function(d) {
if (location.href !== 'https://sodexosaldocartao.com.br/saldocartao/consultaSaldo.do?operation=consult') {
return alert('Você precisa estar na página de `Consulta de Saldo` do seu cartão Sodexo!');
}
var a, transactions = ['Date,Payee,Category,Memo,Outflow,Inflow'],
lines = d.getElementById('gridSaldo').getElementsByTagName('tr'),
cardnumber = d.querySelectorAll('var')[0].innerText.substr(12);
Array.prototype.slice.call(lines).forEach(function(tr, i) {
if (i === 0) {
return true;
}
var outflow = inflow = '',
td = tr.getElementsByTagName('td'),
type = td[2].innerText,
value = td[1].innerText;
if (type === 'CRÉDITO') {
inflow = value;
} else if (type === 'DÉBITO') {
outflow = value;
} else {
return console.error('Tipo `' + type + '` desconhecido!');
}
transactions.push([
td[0].innerText,
td[4].innerText,
'', '',
outflow, inflow
].join(','));
});
ynab = transactions.join("\n");
a = d.createElement('a');
a.target = '_blank';
a.download = 'sodexo_'+ cardnumber + '.csv';
a.href = 'data:attachment/csv;base64,' + btoa(unescape(encodeURIComponent(ynab)));
d.body.appendChild(a);
a.click();
d.body.removeChild(a);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment