steem-python tips #1 - Calculating power-ups!

Powering up


Powering up is a process on steem blockchain where you convert your liquid STEEMs to Steem Power. Every time an account powers up, it broadcast a "transfer_to_vesting" operation to the network.

@sndbox and some other organizations have weekly power-up challenges. And I was lucky to win a couple of them. Today I was curious how much I have powered up in the last month. (I did powered-up a lot.)

Filtering "transfer_to_vesting" ops with steem-python


Out script's main flow should be like this:

  • Get an input with username, start_date, and end_date
  • Filter all "transfer_to_vesting" operations between start_date and end_date
  • Sum all powered-up amount in corresponding transactions.

And we have the number.

Basic example to filter specific operations:

from steem import Steem
from steem.account import Account
s = Steem(nodes=["https://api.steemit.com"])
acc = Account('emrebeyler', steemd_instance=s)
for op in acc.history_reverse(filter_by=["transfer_to_vesting"]):
    print(op)

This script will filter all "transfer_to_vesting" operations in your entire account history and prints them.

The Calculator script


from steem import Steem
from steem.account import Account
from steem.amount import Amount
from dateutil.parser import parse
from datetime import datetime
import tableprint as tp
def calculate_powerup(username, start_date, end_date):
    s = Steem(nodes=["https://api.steemit.com"])
    account = Account(username, steemd_instance=s)
    data = []
    total = 0
    for op in account.history_reverse(filter_by=["transfer_to_vesting"]):
        ts = parse(op["timestamp"])
        if ts > end_date:
            continue
        if ts < start_date:
            break
        total += Amount(op["amount"]).amount
        data.append((op["amount"], op["timestamp"]))
    data.append(("Total: %s STEEM" % round(total, 2), "-"))
    return data, total
if __name__ == '__main__':
    data, total = calculate_powerup(
        'emrebeyler',
        datetime(2018, 2, 1),
        datetime(2018, 3, 1),
    )
    tp.table(data, ['Amount', 'Timestamp'], width=32)

Example output


Screen Shot 2018-03-01 at 14.29.50.png

Seems like I was good powering-up on February!


You can play with other accounts and timeframes by changing start_date and end_date. Make sure you have steem-python and tableprint libraries installed on your local environment.

Have fun.

H2
H3
H4
3 columns
2 columns
1 column
14 Comments