Forked from coleHafner/every-dollar-data-export.js
Last active
October 9, 2022 21:57
-
-
Save dogracer/4c8e03a1853df4bd3e8e638ba6b2343f to your computer and use it in GitHub Desktop.
EveryDollar Data Export
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
// this script allows you to export your data from the EveryDollar budgeting app (everydollar.com) | |
// just paste it in the console after you login and it capture the categories/sub categories, and total spent for the selected month | |
// then it will output a CSV file to the browser | |
// it has only been tested in Chrome on full, non-mobile layout | |
// it's not perfect, but it's good enough. Feel free to tweak it to fit your needs. | |
var lines = []; | |
document.querySelectorAll('.Budget-budgetGroup').forEach(node => { | |
const headerCol = node.getElementsByClassName('BudgetGroupHeader-column')[0]; | |
const spans = headerCol.getElementsByTagName('span'); | |
const groupHeader = spans[1]; | |
const groupText = (spans[1]?.innerText !== '') ? spans[1].innerText : (spans[0]?.innerText !== '') ? spans[0].innerText : ''; | |
const rows = node.getElementsByClassName('BudgetItemRow'); | |
if (!groupText || groupText.toLowerCase().indexOf('favorites') > -1) { | |
return; | |
} | |
if (!rows) { | |
return; | |
} | |
for(let i = 0, len = rows.length; i < len; i++) { | |
const rowNode = rows[i]; | |
const cols = rowNode.getElementsByClassName('BudgetItemRow-column'); | |
var line = []; | |
for (let j = 0, jLen = cols.length; j < jLen; j++) { | |
const col = cols[j]; | |
// category - look for label | |
const label = col.getElementsByClassName('BudgetItem-label'); | |
// planned - look for .BudgetItemRow-input | |
const planned = col.getElementsByClassName('BudgetItemRow-input'); | |
// spent - look for .money | |
const spent = col.getElementsByClassName('money'); | |
if (label && label.length) { | |
const labelInput = label[0].getElementsByTagName('input'); | |
const fixedLabelText = label[0].getAttribute('data-text'); | |
if (labelInput && labelInput.length) { | |
const labelText = labelInput[0].getAttribute('value'); | |
if (line) { | |
line.push(`${groupText}, ${labelText}`); | |
if (groupText !== 'Debt') line.push(' '); | |
} | |
} else if (fixedLabelText && fixedLabelText.length) { | |
if (line) { | |
line.push(`${groupText}, ${fixedLabelText}`); | |
if (groupText !== 'Debt') line.push(' '); | |
} | |
} | |
} | |
else if (planned && planned.length) { | |
const planned_dollas = planned[0].getAttribute('value'); | |
if (line) line.push(planned_dollas.replace('$', '').replace(',', '')); | |
} | |
else if (spent && spent.length) { | |
const dollas = spent[0].getAttribute('data-text'); | |
if (line) line.push(dollas.replace('$', '').replace(',', '')); | |
} | |
} // loop cols | |
if (line && line.length) lines.push(line); | |
} // loop rows | |
}); | |
// export file | |
var fileData = []; | |
fileData.push('Budget Group, Category, Debt Balance, Planned, Received/Remaining/Debt Paid'); | |
lines.forEach(line => { | |
fileData.push(line.join(',')); | |
}); | |
var file = new Blob([fileData.join('\n')], { type: 'text/html'}); | |
var a = document.createElement("a"); | |
var url = URL.createObjectURL(file); | |
a.href = url; | |
var dateAndYear = document.querySelectorAll('.BudgetNavigation-date'); | |
var dateStr = ''; | |
if (dateAndYear) { | |
dateStr = `-${dateAndYear[0].textContent.toLowerCase().replace(' ', '-')}`; | |
} | |
a.download = `budget-summary${dateStr}.csv`; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function() { | |
document.body.removeChild(a); | |
window.URL.revokeObjectURL(url); | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment