How to get the list of your delegator on HIVE/STEEM

in DIGITAL MINE5 years ago

d.png

Hello,

I would like to share with you a very simple python code to get in a very reasonable time frame the list of all the delegators to your account.

Unfortunately there is not a build in function out of the box for this purpose, like to get your outgoing delegations, so a simple work around could get you what you need, but we need to check the whole account transaction history, so that's why I said this solution gives the result in a reasonable time frame.

This code works both for STEEM and HIVE blockchains and it use the last version of beem python library

from beem import Steem
from beem.account import Account
from beem.instance import set_shared_steem_instance
import re

stm = Steem("https://api.hive.blog") #https://api.steemit.com for the steem blockchain
set_shared_steem_instance(stm)
acc = Account("[YOUR ACCOUNT]",steem_instance=stm)

c_list = []
names=[]
for c in acc.history_reverse(only_ops=["delegate_vesting_shares"]):
    data=re.findall("'delegator': '(.+?)'",str(c)),re.findall("'delegatee': '(.+?)'",str(c)),re.findall("'vesting_shares': '(.+?)'",str(c))
    name=re.findall("'delegator': '(.+?)'",str(c))
    if name not in names:
        c_list.append(data)
        names.append(name)
active=[]
removed=[]
for i in c_list:
    if str(i[2])=="['0.000000 VESTS']":
        data=i[0][0],i[2][0]
        removed.append(data)
    else:
        hive=stm.vests_to_sp(float(i[2][0].split(' ')[0]))
        data=i[0][0],hive
        active.append(data)
for i in active:
    print (i[0],':',i[1],'HIVE')
print ('ACTIVE:',len(active))
print ('LOST:',len(removed))
a=input ('Do you want to print the undelgator list?')
if a=='y':
    for i in removed:
        print (i[0],':',i[1],'HIVE')
else:
    exit

As you can see reading the code it ends up by printing the whole list of account and the amount of SP/HP delegates to you, and the number of active delegators and the number of the delegatos who remove their vests to you.
If you want to print the list of the account who remove the delegation you have to type y and click enter, else just click enter and the program will stop.

For any question please leave a message or join me on discrod or twitter

Sort:  

Good stuff! Keep up the good work!   =]

thx m8