Created
April 22, 2020 11:35
-
-
Save fbslo/38fb761049820ab33b4bca9547bb23b6 to your computer and use it in GitHub Desktop.
TeamSlovenia Statistic
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
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