RE: RE: Daily Steem-Python Challenge #8, Win 1 Steem!
You are viewing a single comment's thread from:

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

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

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
H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now