How to get author/curation rewards report in Steem Python

Words
109
Reading
1 min
Listen
Play
9y

Authors may want to see their author/curation rewards report. The Steemit UI provides a very basic report, e.g. only showing report for last week. Sometimes, authors need to see a more flexiable report, e.g. in past 2 weeks / 1 month etc. Here is how to do it by using Steem Python library.

image.png

First you need to make sure Steem Python is installed. If not, please refer to its documentation: https://github.com/steemit/steem-python

Now we are ready to write the script. Create a file e.g. listawards.py with the following code:

from sys import argv
from steem.account import Account
from datetime import datetime, timedelta
from steem import converter
import sys

if len(sys.argv) !=3:
  print ('Usage: python listawards.py ACCOUNT NUMBER_OF_DAYS')
  exit()
user  = argv[1]
_days = int(argv[2])
cv = converter.Converter()

records_to_check=10000

account = Account(user)
history = account.get_account_history(index=-1, limit=records_to_check)

total_curation_reward = 0
total_author_sbd = 0
total_author_sp  = 0

for h in history:
  oper_type = h['type']
  if oper_type=='curation_reward':
    _time  = datetime.strptime(h['timestamp'], '%Y-%m-%dT%H:%M:%S')
    if _time + timedelta(days = _days) >= datetime.now():
      reward = float(h['reward'].replace(' VESTS', ''))
      total_curation_reward += reward
    else:
      break
  elif oper_type=='author_reward':
    total_author_sbd += float(h['sbd_payout'].replace(' SBD', ''))
    total_author_sp  += float(h['vesting_payout'].replace(' VESTS', ''))

print("Author: %.2f SBD, %.2f SP" % (total_author_sbd, cv.vests_to_sp(total_author_sp)))
print("Curation: %.2f SP" % cv.vests_to_sp(total_curation_reward))

To run the script, type:

python listawards.py yuxid 14

Change the parameters to see other users report, e.g.

python listawards.py utopian-io 7



Posted on Utopian.io - Rewarding Open Source Contributors

How to get author/curation rewards report in Steem Python | Ecency