Steem-Python for dummies #2 - Playing with accounts

in #utopian-io7 years ago

In the last post, we had set-up our development environment and learned how to create posts, comments, upvotes, and transfers in the blockchain.

In the second part of the "SteemPython for dummies" series, we will play with accounts in the blockchain. You can see the first part here.

Account data

Let's get the initial, public data of an account in the chain.

from steem.account import Account
account = Account('emrebeyler')
print(account)

This will print lots of data about my account. Since the output is huge, you can check an example response from here.

Three of useful metrics in that data are:

  • Reputation Points
  • Voting Powers (Percent)
  • Steem Power

1. Calculating Reputation Point

account data has a field of reputation which looks like a big number like this:

'reputation': '6458590899303',

This is not actually what we see in the Steemit interface (condenser). Condenser has an implementation to transform this value into a readable format. parsersAndFormatters.js in condenser source

steem-python package has a helper function trying to do the same for us, let's try it.

acc = Account('emrebeyler',  steemd_instance=s)
print("Raw Reputation point: %s" % acc["reputation"])
print("Calculated Reputation: %s" % acc.rep)

Output:

Raw Reputation point: 6458590899303
Calculated Reputation: 59.29

We can just use account.rep property to get the formatted point.

Tip: Currently, steem-python package has a little bug which results with miscalculated reputation points. (after formatting) You can see a potential solution and a pull request of mine here.

2. Calculating effective SP

Our effective steem power formula is easy:

total_sp = owned_sp + received_sp - delegated_sp

Let's implement this formula and find out my effective Steem Power.

To implement the SP amount of an account:

sp_vests = Amount(acc['vesting_shares']).amount
total_sp = round(acc.converter.vests_to_sp(sp_vests), 3)

For the received delegation and outgoing delegations:

received_vests = Amount(acc['received_vesting_shares']).amount
received_sp = round(acc.converter.vests_to_sp(received_vests), 3)
delegated_vests = Amount(acc['delegated_vesting_shares']).amount
delegated_sp = round(acc.converter.vests_to_sp(delegated_vests), 3)

Tip: Some of the data bounded to profile are VESTS which we can convert them to SP with a helper method steem-python. Package has a class of Converter which you can convert a lot of things like:

  • sp to vests
  • sp to rshares
  • steem to sbd
  • sbd to steem
  • sbd to rshares

Let's get back to calculating effective SP, Since I have all I need to calculate it, let's do the math.

print(total_sp + received_sp - delegated_sp)

will print my account's effective SP. (It should be around 843 now. It's hard to be a minnow.)

3. Calculating Voting Power

This is tricky topic. Let's get my account's voting power.

print(acc["voting_power"])

It returns an integer as 9141. Just divide it by 100, and you get the actual voting power.

But this is not up to date voting power. That caused a bug at steem.rocks. It turns out the data you get here is the voting power on the last vote time which is also specified in the account data.

Based on vote regeneration constants and last vote time, we can calculate up-to-date voting power ourselves.

Here is a simple implementation to calculate it right. Click the image to get the raw code.


That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  
Qurator
Your Quality Content Curator
This post has been upvoted and given the stamp of authenticity by @qurator. To join the quality content creators and receive daily upvotes click here for more info.

Qurator's exclusive support bot is now live. For more info click HERE or send some SBD and your link to @qustodian to get even more support.

Feel free to ask questions or request topics about steem-python for the incoming posts.

I feel lazy for even asking, as I'm waiting for a painfully slow software update to finish and can't play with this yet myself, but...
Do you know how to fetch the view count for a post and whether fetching it changes it?

views are not really blockchain's thing. It's steemit's addition to its interface. Operations outside of the steemit web dont increase that counter.

That's what I suspected, due to the nature of the blockchain.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

This helps to get started. Thanks

Hey @emrebeyler I am @utopian-io. I have just upvoted you at 7% Power!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • I introduced a competition factor. My vote is based also on how competitive the category used is.

Human Curation

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Haver another happy year, !BEER



Hey @emrebeyler, here is a little bit of BEER from @isnochys for you. Enjoy it!

Coin Marketplace

STEEM 0.20
TRX 0.20
JST 0.034
BTC 89846.05
ETH 3077.33
USDT 1.00
SBD 2.96