How to Compute Steem Power and Construct a SteemConnect Delegation URL Using steem-python

in #steemit6 years ago (edited)

This post contains two Python scripts that show how to use the classes in the steem-python library to compute the Steem Power of an account and construct a SteemConnect URL for delegation purposes.

These scripts use the steem-python "Converter" class. Converter functions can be used on "Account", "Converter", and "Commit" objects. In these scripts I make a Converter object to use the functions.

Tips on installing and using steem-python on an Apple or Linux computer
Download and install steem-python
Download and install Python

Print out a user's SP

# Use steem-python to determine an account's steem power.

from steem.account import Account
from steem.amount import Amount
from steem.converter import Converter

# Substitute another username for "numberjocky".

userName = 'numberjocky'

# Retrieve the account of the user.

userAcct = Account(userName)

# Get a Converter object.

c = Converter()

# Compute the Steem Power from the account's vesting shares.  Use the "Amount" class
# because the value of the "vesting_shares" key is a two-word string.

spVests = Amount(userAcct['vesting_shares']).amount

# Use the Converter object to convert VESTS to SP

userSP = c.vests_to_sp(spVests)

# Print out the account's Steem Power

print("%s" % userName)
print("%.3f SP" % userSP)

Print out a delegation URL

# Use steem-python to print out a delegation URL

from steem.account import Account
from steem.amount import Amount
from steem.converter import Converter

# Substitute another username for "numberjocky".

userName = 'numberjocky'

# Substitute the name of a user to delegate to instead of "minnowsupport".

delegateTo = 'minnowsupport'

# Substitute the amount of Steem Power to delegate instead of "10". 

spToDelegate = 10

# Get a Converter object

c = Converter()

# Retrieve "steem per mvests" using the Converter object.  This number changes from 
# day to day.

steemPerMVests = c.steem_per_mvests()

# Compute how many vests to delegate.

vestsToDelegate = 1000000/steemPerMVests*spToDelegate

# Print out a URL to use Steem Connect for delegation.

preStr = "https://v2.steemconnect.com/sign/delegateVestingShares?delegator"
dStr = "&delegatee"
vStr = "&vesting_shares"
sufStr = "%20VESTS"
printVariables = (preStr,userName,dStr,delegateTo,vStr,vestsToDelegate,sufStr)

print("%s=%s%s=%s%s=%.6f%s" % printVariables)

Copy the URL and paste it in your browser to delegate SP.

Enjoy!

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98914.40
ETH 3374.27
USDT 1.00
SBD 3.08