Created
March 12, 2018 04:51
-
-
Save TGOlson/0aa948abe8fe978c2a768b4374455a4e to your computer and use it in GitHub Desktop.
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
(async function() { | |
// Volume,Symbol,Date Acquired,Date Sold,Proceeds,Cost Basis,Gain,Currency | |
const csv = []; | |
const formatDate = dateStr => dateStr.slice(5).replace('-', '/') + '/' + dateStr.slice(0, 4); | |
const rows = csv.map(row => { | |
const [volume, symbol, acquired, sold, proceeds, costBasis, gain, currency] = row.split(","); | |
const description = `${volume} ${symbol}`; | |
return { | |
description, | |
proceeds, | |
saleDate: formatDate(sold), | |
costBasis, | |
dateAcquired: formatDate(acquired) | |
}; | |
}); | |
async function run(pageDelay) { | |
console.log('running import with page delay', pageDelay); | |
for(let i = 0; i < rows.length; i++) { | |
const row = rows[i]; | |
console.log('importing row', row); | |
await runIteration(pageDelay, row); | |
document.getElementById('Yes_00').click(); | |
await sleep(pageDelay); | |
} | |
console.log('done!'); | |
} | |
async function runIteration(pageDelay, row) { | |
const set = (id, value) => { | |
const el = document.getElementById(id); | |
el.value = value | |
el.dispatchEvent(new KeyboardEvent('keyup')); | |
el.dispatchEvent(new MouseEvent('blur')); | |
} | |
async function cont() { | |
// await sleep(pageDelay); // uncomment for debug | |
document.getElementById('Continue_00').click(); | |
await sleep(pageDelay); | |
} | |
document.getElementById('radio_0e:0').click(); | |
await cont(); | |
set('edt_00', row.description); | |
set('edt_01', row.proceeds); | |
set('edt_02', row.saleDate); | |
await cont(); | |
document.getElementById('radio_00:4').click(); | |
await cont(); | |
set('edt_00', row.costBasis); | |
set('edt_01', row.dateAcquired); | |
await cont(); | |
await cont(); | |
} | |
async function sleep(millis) { | |
return new Promise(resolve => setTimeout(resolve, millis)); | |
} | |
await run(1000); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment