How to Retrieve Steem and SBD Balance and Voting Power of Your Account Using Python

in #steemit6 years ago (edited)

The script below retrieves the Steem Balance, the SBD Balance, and calculates the current Voting Power for a user's account. It can be run from the command line on a Unix system (such as Apple) or Linux system by putting the path to the python executable at the top of the text file that the script is in.

Before running the script, the steem-python package must be installed using pip or pip3.

I usually run the script in IDLE and see the output there. Here is the script:

# This script will print out the SBD and STEEM balances and the voting
# power of a Steemit user.

from steem import Steem
from datetime import datetime

s = Steem()

# Substitute your username for "numberjocky".
userName = 'numberjocky'

# The present UTC time will be used to compute voting power.
timeNow = datetime.utcnow()

# Get the account data for userName
userAcct = s.get_account(userName)

# The SBD and Steem balances of the account are the values of the 
# "sbd_balance" and "balance" keys in the userAcct dictionary
#  object.  The values are two-word strings so they need to be split and 
# the first element of the resulting list is the value of the balance.
sbdBalance = userAcct['sbd_balance'].split()[0]
steemBalance = userAcct['balance'].split()[0]

# The voting_power and last_vote_time store the voting power of the 
# user the last time they voted.  To compute the present voting power, 
# the last_vote_time must be subtracted from the present time and the 
# difference multiplied by the vote replenishment factor of 20% per day.
# Then, the result is added to the voting power at the last vote time to 
# determine the current voting power.
votingPowerLast = userAcct['voting_power']/100
lastVoteTime = datetime.strptime(userAcct['last_vote_time'],'%Y-%m-%dT%H:%M:%S')
timeBeforeNow = timeNow-lastVoteTime
votingPowerNow = timeBeforeNow.seconds*20/86400+votingPowerLast
if votingPowerNow > 100.0:
    votingPowerNow = 100.0
    
# Print out the results.    
print("%s" % userName)
print("%s SBD" % sbdBalance)
print("%s STEEM" % steemBalance)
print("%.5s voting power" % votingPowerNow)

Enjoy!

Sort:  

Go here https://steemit.com/@a-a-a to get your post resteemed to over 72,000 followers.

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.031
BTC 67128.03
ETH 3788.25
USDT 1.00
SBD 3.74