create account

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

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @steempytutorials/daily-steem-python-challenge-8-win-1-steem

· @luj1 ·
$0.19
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
👍  ,
properties (23)
authorluj1
permlinkre-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t201210185z
categorycontest
json_metadata{"tags":["contest"],"app":"steemit/0.1"}
created2018-01-20 20:12:09
last_update2018-01-20 20:12:09
depth1
children4
last_payout2018-01-27 20:12:09
cashout_time1969-12-31 23:59:59
total_payout_value0.150 HBD
curator_payout_value0.036 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,023
author_reputation913,538,372
root_title"Daily Steem-Python Challenge #8, Win 1 Steem!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,943,347
net_rshares16,569,240,482
author_curate_reward""
vote details (2)
@amosbastian ·
Like @maxg  said you need to take the user's current vote power into account!
properties (22)
authoramosbastian
permlinkre-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t140903117z
categorycontest
json_metadata{"tags":["contest"],"users":["maxg"],"app":"steemit/0.1"}
created2018-01-21 14:09:03
last_update2018-01-21 14:09:03
depth2
children1
last_payout2018-01-28 14:09:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length77
author_reputation174,473,586,900,705
root_title"Daily Steem-Python Challenge #8, Win 1 Steem!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,115,103
net_rshares0
@luj1 ·
Ah, right, maybe next time :)
properties (22)
authorluj1
permlinkre-amosbastian-re-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t153137951z
categorycontest
json_metadata{"tags":["contest"],"app":"steemit/0.1"}
created2018-01-21 15:31:39
last_update2018-01-21 15:31:39
depth3
children0
last_payout2018-01-28 15:31:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation913,538,372
root_title"Daily Steem-Python Challenge #8, Win 1 Steem!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,132,921
net_rshares0
@juliank ·
I love how quick you are! @amosbastian will be going over your code tomorrow
properties (22)
authorjuliank
permlinkre-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t213639568z
categorycontest
json_metadata{"tags":["contest"],"users":["amosbastian"],"app":"steemit/0.1"}
created2018-01-20 21:36:39
last_update2018-01-20 21:36:39
depth2
children0
last_payout2018-01-27 21:36:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length76
author_reputation117,823,071,447,502
root_title"Daily Steem-Python Challenge #8, Win 1 Steem!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,956,878
net_rshares0
@maxg ·
I think you need to take the user's current vote power into account, too
properties (22)
authormaxg
permlinkre-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t205029873z
categorycontest
json_metadata{"tags":["contest"],"app":"steemit/0.1"}
created2018-01-20 20:50:30
last_update2018-01-20 20:50:30
depth2
children0
last_payout2018-01-27 20:50:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length72
author_reputation5,859,582,764,121
root_title"Daily Steem-Python Challenge #8, Win 1 Steem!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,949,626
net_rshares0