Save Your Curation Rewards Grouped By Date Using Node JS
steem·@reazuliqbal·
0.000 HBDSave Your Curation Rewards Grouped By Date Using Node JS
 We all have seen a rewards table right at the top of our steemworld.org profile page. You can get a idea about your daily curation and author SP, and earnings of SBD and STEEM for last 6 days. This is an awesome website to check anyone's earnings stats and activities. This got me thinking how much curation rewards I have earned daily from the day I joined Steem. So, I wrote this Node.JS script to loop through my account history to check and group curations rewards by their date. This function do all the looping through - 5000 items per loop. It checked for curation reward entries and push them to an array with their date for further processing. When looping is completed the `callback` groups all the records by their dates from that array and returns an object. ``` const getCuration = async (account, start, callback) => { let lastTrans = start; await client.database.call('get_account_history', [account, start, (start < 0) ? 5000 : Math.min(start, 5000)]) .then((result) => { result.reverse(); for (let i = 0; i < result.length; i += 1) { const trans = result[i]; const { op } = trans[1]; // Checking on curation rewards and pushing them to an array by their date if (op[0] === 'curation_reward') { const rdate = new Date(`${trans[1].timestamp}Z`); const ndate = `${rdate.getMonth() + 1}/${rdate.getDate()}/${rdate.getFullYear()}`; curationReward.push({ time: ndate, reward: op[1].reward }); } // Save the ID of the last transaction that was processed. [lastTrans] = trans; } if (lastTrans > 0 && lastTrans !== start) { // Looping through all the account history getCuration(account, lastTrans, callback); } else { // Grouping the rewards by date and making a new object callback(curationReward.reduce((acc, obj) => { const key = obj.time; if (!acc[key]) { acc[key] = []; } acc[key].push(obj.reward.replace(' VESTS', '')); return acc; }, {})); } }); }; ``` In the Self-Invoking anonymous function we call the above function and process the returned object. We add all the VEST for each day, convert them to SP, and save them to another array with their dates to write to a readable JSON file. ``` // Replace `reazuliqbal` with your username await getCuration('reazuliqbal', -1, (data) => { const rewards = []; // Adding all rewards for each day and converting them to SP Object.keys(data).forEach((d) => { const reward = data[d].reduce((a, b) => a + parseFloat(b), 0); rewards.push({ date: d, reward: `${vestToSP(reward)} SP` }); }); // Writing the result to a readable JSON file fs.writeFileSync('rewards.json', JSON.stringify(rewards, null, 4)); }); ``` For a old account with lots of activities it will take a long time depending on your internet connection and device. For my account in my laptop it takes 30 seconds or so. Check out the full code on this [Gist](https://gist.github.com/CodeBull/6e93bdcf8309b6a04c1d484d00e41a47) and if you have any suggestions, feel free to comment. <sup>Code screenshot was taken using this awesome [project](https://github.com/dawnlabs/carbon).</sup>
👍 lusinehakobyan, snailrepeat, nfc, wallskirk, xlibanti, olegtimenkov, crayoncamera, dinasamoilova, semenovyx83, needlesten, ringwormbasic, referrednut, maslov11, blazarpastebin, sodgelatin, narkojen, polfilds, zcool, noblebot, themesopotamians, particleman, m-ashurbanipal, sourovafrin, sbi2, pataty69, aleister, renatomacedo, portugalcoin, enlighted, duarte9sousa, munhenhos, bhaski, dexterdoggy, roc.green, hr1, arcange, steemitbd, steemtaker, jahedkhan, alexran, mhmuhib, tazinidos, hkabir62, raphaelle, mhossain, caps, zaku, arcanu, venusisme, bdvoter, sfturzo, wrestleredoy, ayasha, azizbd, longberry, steemhq, davidding, billbutler, kaylinart, velourex, brains, brimax, steemsportsfund, anforo, andyluy, lisaocampo, steps, rockz, sniffbiff, angelol, brittuf, gogogadgetupvote, kassixo, tpot, jerseynash, lucentbritex, shartzy, eoss, steem.services, zappos, steemitbuilder, city-of-berlin, timetraveljesus, rannarvasa1, henroo84, steemitbuzz, dahaz159, primus, themonetaryfew, ozoo, upheaver, spectrumecons, robertking, onetin84, dong262514, tomiscurious, bestgift, pedrojunior, sugardash, yb1337, aes-exchange, bekirsolak, saiduzzaman, sabbir1213, lordnigel, etcmike,