Created
October 14, 2018 12:18
-
-
Save reazuliqbal/060ae962e465bce13066917eb69982db 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
const wlsjs = require('@whaleshares/wlsjs'); | |
wlsjs.api.setOptions({ url: 'https://rpc.wls.services' }); | |
(async () => { | |
const username = 'reazuliqbal'; | |
const fortnightAgo = new Date(Date.now() - 12096e5); | |
const calcTotal = object => (object.reduce((acc, cur) => (parseFloat(cur.pendingPayout) + acc), 0)).toFixed(2); | |
console.log('Total Pending Rewards:'); | |
const posts = await wlsjs.api.getDiscussionsByAuthorBeforeDateAsync(username, null, new Date().toISOString().split('.')[0], 100); | |
const newPosts = posts.filter(p => new Date(`${p.created}Z`) >= fortnightAgo); | |
const postRewards = newPosts.map(p => ({ | |
author: p.author, | |
permlink: p.permlink, | |
pendingPayout: p.pending_payout_value, | |
})); | |
console.log(`Posts: ${calcTotal(postRewards)}`); | |
const comments = await wlsjs.api.getStateAsync(`@${username}/comments`); | |
const commentRewards = []; | |
Object.keys(comments.content).forEach((key) => { | |
const comment = comments.content[key]; | |
const created = new Date(`${comment.created}Z`); | |
if (created >= fortnightAgo) { | |
commentRewards.push({ | |
author: comment.author, | |
permlink: comment.permlink, | |
pendingPayout: comment.pending_payout_value, | |
}); | |
} | |
}); | |
console.log(`Comments: ${calcTotal(commentRewards)}`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment