Skip to content

Instantly share code, notes, and snippets.

@fbslo
Created April 22, 2020 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbslo/38fb761049820ab33b4bca9547bb23b6 to your computer and use it in GitHub Desktop.
Save fbslo/38fb761049820ab33b4bca9547bb23b6 to your computer and use it in GitHub Desktop.
TeamSlovenia Statistic
var hive = require('steem-js-patched')
hive.api.setOptions({ url: 'https://api.hive.blog' });
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var balance = 0.000
var sbd_balance = 0.000
var totalSteem;
var totalVests;
var hp = 0.000
var users = '{"result":[]}'
var obj = JSON.parse(users);
async function run(){
hive.api.getDynamicGlobalProperties((err, result) => {
totalSteem = Number(result.total_vesting_fund_steem.split(' ')[0]);
totalVests = Number(result.total_vesting_shares.split(' ')[0]);
})
await sleep(2000)
hive.api.getFollowing('teamslovenia', 0, null, '1000', async function(err, result) {
for(i=0;i<result.length;i++){
hive.api.getAccounts([result[i].following], async function(err2, result2) {
balance += Number((result2[0].balance).split(' ')[0])
sbd_balance += Number((result2[0].sbd_balance).split(' ')[0])
var userVests = Number(result2[0].vesting_shares.split(' ')[0])
hp += +(totalSteem * (userVests / totalVests)).toFixed(3)
console.log('User '+result2[0].name +' with balance '+result2[0].balance+' and '+result2[0].sbd_balance+' and '+ (totalSteem * (userVests / totalVests)).toFixed(3)+' HP!')
console.log('Total: ' + balance.toFixed(3) +' HIVE and '+sbd_balance.toFixed(3) + ' HBD and '+hp.toFixed(3)+' HP!')
obj["result"].push({"user": result[i].following, "hive": result2[0].balance.split(" ")[0], "hbd": result2[0].sbd_balance.split(" ")[0], "hp": (totalSteem * (userVests / totalVests)).toFixed(3)})
});
await sleep(1000)
}
console.log(obj)
});
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment