How to get author/curation rewards report in Steem Python

in #utopian-io7 years ago

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

Sort:  

Hey @yuxid I am @utopian-io. I have just upvoted you!

Achievements

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

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

Wow nice,,, i will try this

Congratulations @yuxid! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Thank you for the contribution. It has been approved.

P.S: Just tried the script, works well! :)

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

This post upvoted 5% power by @Utopy - [Support Contributors ]
image.png

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 90661.84
ETH 3146.93
USDT 1.00
SBD 2.98