create account

Save Your Curation Rewards Grouped By Date Using Node JS by reazuliqbal

View this thread on: hive.blogpeakd.comecency.com
· @reazuliqbal ·
$16.79
Save Your Curation Rewards Grouped By Date Using Node JS
![carbon.png](https://ipfs.busy.org/ipfs/QmaDNwKfka46yWDkkkQLFLXW8TMdMMWPKKVySzHAvgEghb)

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>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 42 others
properties (23)
authorreazuliqbal
permlinksave-your-curation-rewards-grouped-by-date-using-node-js
categorysteem
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["steem","steemdev","curation","rewards","dsteem"],"users":[],"links":["https://gist.github.com/CodeBull/6e93bdcf8309b6a04c1d484d00e41a47","https://github.com/dawnlabs/carbon"],"image":["https://ipfs.busy.org/ipfs/QmaDNwKfka46yWDkkkQLFLXW8TMdMMWPKKVySzHAvgEghb"]}
created2018-09-16 14:10:21
last_update2018-09-16 14:10:21
depth0
children3
last_payout2018-09-23 14:10:21
cashout_time1969-12-31 23:59:59
total_payout_value12.911 HBD
curator_payout_value3.875 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,386
author_reputation61,984,354,446,410
root_title"Save Your Curation Rewards Grouped By Date Using Node JS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,451,722
net_rshares13,883,186,167,542
author_curate_reward""
vote details (106)
@saiduzzaman ·
You have recieved a free upvote from @saiduzzaman . For Nice Article . Carry On Brother
properties (22)
authorsaiduzzaman
permlinkre-reazuliqbal-save-your-curation-rewards-grouped-by-date-using-node-js-20180918t223459335z
categorysteem
json_metadata{"tags":["steem"],"users":["saiduzzaman"],"app":"steemit/0.1"}
created2018-09-18 22:35:03
last_update2018-09-18 22:35:03
depth1
children0
last_payout2018-09-25 22:35:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length87
author_reputation8,880,536,199,903
root_title"Save Your Curation Rewards Grouped By Date Using Node JS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,621,928
net_rshares0
@steemhq ·
re-reazuliqbal-save-your-curation-rewards-grouped-by-date-using-node-js-20180917t050615057z
![YOU JUST GOT UPVOTED](https://www.steemhq.com/CommunityBotUpvote.png)

**Congratulations,**
you just received a 15.80% upvote from @steemhq - Community Bot!

***Wanna join and receive free upvotes yourself?***
Vote for `steemhq.witness` on [Steemit](https://steemit.com/~witnesses) or directly on [SteemConnect](https://steemconnect.com/sign/account-witness-vote?witness=steemhq.witness&approve=1 "This link will take you away from steemit.com") and join the [Community Witness](https://www.steemhq.com/witness).
![](https://steemitimages.com/0x0/https://www.steemhq.com/steemhq_voting.gif)

This service was brought to you by [SteemHQ.com](https://www.steemhq.com)
properties (22)
authorsteemhq
permlinkre-reazuliqbal-save-your-curation-rewards-grouped-by-date-using-node-js-20180917t050615057z
categorysteem
json_metadata{"app":"communitybot/1.1.0"}
created2018-09-17 05:06:15
last_update2018-09-17 05:06:15
depth1
children0
last_payout2018-09-24 05:06:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length667
author_reputation4,219,992,220,673
root_title"Save Your Curation Rewards Grouped By Date Using Node JS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,506,894
net_rshares0
@tts ·
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/reazuliqbal__save-your-curation-rewards-grouped-by-date-using-node-js.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvoting this reply.
properties (22)
authortts
permlinkre-save-your-curation-rewards-grouped-by-date-using-node-js-20180916t150123
categorysteem
json_metadata""
created2018-09-16 15:01:24
last_update2018-09-16 15:01:24
depth1
children0
last_payout2018-09-23 15:01:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length379
author_reputation-4,535,154,553,995
root_title"Save Your Curation Rewards Grouped By Date Using Node JS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,455,685
net_rshares0