RE: Daily Steem-Python Challenge #8, Win 1 Steem!

You are viewing a single comment's thread from:

Daily Steem-Python Challenge #8, Win 1 Steem!

in contest •  7 years ago 

Sadly I'm not able to test the code at the moment as I'm writing from my mobile, but it should look like this:

from steem import Steem
from steem.blockchain import Blockchain
from steem.amount import Amount
from steem.account import Account
import json
import datetime

def converter(object_):
    if isinstance(object_, datetime.datetime):
        return object_.__str__()

def run():
    steem = Steem()
    blockchain = Blockchain()
    stream = blockchain.stream(filter_by=["transfer"])

    username = "amosbastian"

    account = Account(username)

    reward_fund = steem.get_reward_fund()
    reward_balance = Amount(reward_fund["reward_balance"]).amount
    recent_claims = float(reward_fund["recent_claims"])
    reward_share = reward_balance / recent_claims
    base = Amount(steem.get_current_median_history_price()["base"]).amount

    while True:
        try:
            for transfer in stream:
                if transfer["to"] == username:
                    url, permlink = transfer["memo"].split("@")
                    if "https://steemit.com/" in url:
                        vests = account.get_balances()['available']['VESTS']
                        vp = vests * 0.02

                        value = vp * base * reward_share
                        
                        p = float(str(transfer["amount"]).replace(" STEEM", "")) * base
                        
                        if value < p:
                            steem.vote(f"@{permlink}", 100)
                            refund = p - value
                            steem.transfer(transfer['from'], amount=refund, asset="SBD", account=username)
                        else:
                            steem.vote(f"@{permlink}", 100 * (p/value))
        except Exception as error:
            print(repr(error))
            continue
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!
Sort Order:  

I think you need to take the user's current vote power into account, too

I love how quick you are! @amosbastian will be going over your code tomorrow

Like @maxg said you need to take the user's current vote power into account!

Ah, right, maybe next time :)