Claiming Rewards Tool Snippet

in steembin •  7 years ago 

View on SteemBin


#!/usr/bin/env python3

import requests
import click
import sys

unclaimed_msg = """
You have unclaimed rewards on Steemit!
Visit https://steemit.com/@{user}/transfers to redeem:
{sbd:.3f} SBD
{steem:.3f} STEEM
"""

claimed_msg = """
No unclaimed rewards at this time. Check again soon!
"""

error_msg = """
Unable to find a wallet for the user {user}. Please check your spelling and try again.
"""

@click.command()
@click.option('--quiet', is_flag=True)
@click.argument('user')
def check_unclaimed_rewards(user, quiet):
    data = requests.get(f'https://steemit.com/@{user}.json').json()
    if data['status'] == '404':
        if not quiet:
            print(error_msg.format(user=user))
        sys.exit(1)

    pending_sbd = data['user']['reward_sbd_balance'].split(' ')[0]
    pending_steem = data['user']['reward_vesting_steem'].split(' ')[0]

    pending_sbd = float(pending_sbd)
    pending_steem = float(pending_steem)

    if pending_steem > 0 or pending_sbd > 0:
        print(unclaimed_msg.format(**{
            'user':user,
            'sbd': pending_sbd,
            'steem': pending_steem
            }))
    elif not quiet:
        print(claimed_msg)

    sys.exit(0)
    
if __name__ == '__main__':
    check_unclaimed_rewards()

View on SteemBin

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!