-
-
Save leandropls/97c22d9eef99946d7fafd6011a52b1c5 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment