Last active
June 28, 2022 05:24
-
-
Save renanmpimentel/d07646fda10e924a1143c84a0bd6eeaf to your computer and use it in GitHub Desktop.
Script para gerar arquivo OFX de cartões de credito santander. ( Baseado https://github.com/gushonorato/nubank-ofx )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function startOfx() { | |
return ` | |
OFXHEADER:100 | |
DATA:OFXSGML | |
VERSION:102 | |
SECURITY:NONE | |
ENCODING:USASCII | |
CHARSET:1252 | |
COMPRESSION:NONE | |
OLDFILEUID:NONE | |
NEWFILEUID:NONE | |
<OFX> | |
<BANKMSGSRSV1> | |
<STMTTRNRS> | |
<STMTRS> | |
<BANKTRANLIST>`; | |
} | |
function endOfx() { | |
return ` | |
</BANKTRANLIST> | |
</STMTRS> | |
</STMTTRNRS> | |
</BANKMSGSRSV1> | |
</OFX>`; | |
} | |
function bankStatement(date, amount, description) { | |
return ` | |
<STMTTRN> | |
<TRNTYPE>OTHER</TRNTYPE> | |
<DTPOSTED>${date}</DTPOSTED> | |
<TRNAMT>${amount}</TRNAMT> | |
<MEMO>${description}</MEMO> | |
</STMTTRN>`; | |
} | |
function normalizeAmount(text) { | |
return text.replace('.', '').replace(',','.'); | |
} | |
function normalizeDate(date) { | |
date = date.split('/'); | |
return date[2]+date[1]+date[0] | |
} | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function generateOfx() { | |
var dollar = parseFloat(normalizeAmount(getElementByXpath('//*[@id="resdespbra"]/table/tbody/tr[1]/td[3]/table/tbody/tr[4]/td[2]/strong').innerText)) | |
var ofx = startOfx(); | |
var inputs = document.querySelectorAll('.trClaro'); | |
inputs.forEach(function(el, index, array){ | |
var date = normalizeDate(el.getElementsByTagName('td')[0].innerText); | |
var description = el.getElementsByTagName('td')[1].innerText; | |
if(normalizeAmount(el.getElementsByTagName('td')[3].innerText) > 0) { | |
var amount = normalizeAmount(el.getElementsByTagName('td')[3].innerText) * dollar; | |
} else { | |
var amount = normalizeAmount(el.getElementsByTagName('td')[2].innerText); | |
} | |
ofx += bankStatement(date, amount, description); | |
}); | |
ofx += endOfx(); | |
console.log(ofx); | |
} |
Vou testar seu script, @delanohelio. Muito obrigado.
Pessoal, fiz uma tentativa de resolver pra mim no Neon Pejota tambem, mas tentei fazer uma engine mais flexivel. Se quiserem testar no Santander, seria bem legal... Só precisa adicionar o schema com os selectors certos!
Olá pessoal,
Eu criei uma extensão que está disponível aqui (https://github.com/delanohelio/santander-export-extension). O propósito foi gerar o OFX para usar no Organnize.
Tem funcionado para mim.
Como faço para utilizar?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá pessoal,
Eu criei uma extensão que está disponível aqui (https://github.com/delanohelio/santander-export-extension). O propósito foi gerar o OFX para usar no Organnize.
Tem funcionado para mim.