<center>https://cdn.discordapp.com/attachments/404587860872921088/405329216280723458/challenge.png</center> For each tutorial we release there will be a relevant challenge where the winner receives 1 STEEM! ### Challenge Today's challenge is a little bit more difficult than usual. Take the code from the tutorial from [here](https://github.com/amosbastian/steempy-tutorials/blob/master/part_8/memo.py) and change it to be able to do the following 1. Calculate how much your 100% upvote is worth, then upvote the specified post with an upvote that is equal to the received SBD (so if it's less, you should refund the difference)! That's it! Good luck to everyone participating! ### Deadline The prize money will be rewarded to the person that solves the problem first. If there is no solution within 7 days after this post has been submitted the prize pool expires. ### Relevant Tutorial [How To Create Your Own Upvote Bot Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-8-how-to-create-your-own-upvote-bot-using-steem-python) --- If you have questions about the tutorial or the challenge then don't hesitate to comment below or contact us on [Discord](https://discord.gg/rYTV87W)!
author | steempytutorials |
---|---|
permlink | daily-steem-python-challenge-8-win-1-steem |
category | contest |
json_metadata | {"tags":["contest","python","bot","programming"],"image":["https://cdn.discordapp.com/attachments/404587860872921088/405329216280723458/challenge.png"],"links":["https://github.com/amosbastian/steempy-tutorials/blob/master/part_8/memo.py","https://steemit.com/utopian-io/@steempytutorials/part-8-how-to-create-your-own-upvote-bot-using-steem-python","https://discord.gg/rYTV87W"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-01-20 19:17:21 |
last_update | 2018-01-23 15:18:42 |
depth | 0 |
children | 11 |
last_payout | 2018-01-27 19:17:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 4.678 HBD |
curator_payout_value | 0.054 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,218 |
author_reputation | 31,094,047,689,691 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,933,598 |
net_rshares | 415,811,357,937 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
amrizal | 0 | 695,695,570 | 100% | ||
juliank | 0 | 392,779,276,059 | 30% | ||
sammie85 | 0 | 408,985,529 | 100% | ||
kiokizz | 0 | 5,945,583,966 | 29% | ||
emrebeyler | 0 | 2,434,032,062 | 7% | ||
besthelal03 | 0 | 190,893,480 | 100% | ||
serafim372 | 0 | 50,000,045 | 100% | ||
maxg | 0 | 1,313,703,721 | 100% | ||
amosbastian | 0 | 6,783,864,879 | 100% | ||
davidamsterdam | 0 | 98,431,372 | 100% | ||
veenox | 0 | 174,734,372 | 100% | ||
jtomes123 | 0 | 614,540,958 | 100% | ||
steempytutorials | 0 | 2,646,188,204 | 100% | ||
nourtawfiq | 0 | 305,150,545 | 100% | ||
denispenyok | 0 | 448,566,115 | 100% | ||
luj1 | 0 | 513,085,848 | 100% | ||
yz0rgc0rpb | 0 | 408,625,212 | 100% |
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
author | luj1 |
---|---|
permlink | re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t201210185z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-20 20:12:09 |
last_update | 2018-01-20 20:12:09 |
depth | 1 |
children | 4 |
last_payout | 2018-01-27 20:12:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.150 HBD |
curator_payout_value | 0.036 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,023 |
author_reputation | 913,538,372 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,943,347 |
net_rshares | 16,569,240,482 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
juliank | 0 | 13,782,217,442 | 1% | ||
steempytutorials | 0 | 2,787,023,040 | 100% |
Like @maxg said you need to take the user's current vote power into account!
author | amosbastian |
---|---|
permlink | re-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t140903117z |
category | contest |
json_metadata | {"tags":["contest"],"users":["maxg"],"app":"steemit/0.1"} |
created | 2018-01-21 14:09:03 |
last_update | 2018-01-21 14:09:03 |
depth | 2 |
children | 1 |
last_payout | 2018-01-28 14:09:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 77 |
author_reputation | 174,473,586,900,705 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 31,115,103 |
net_rshares | 0 |
Ah, right, maybe next time :)
author | luj1 |
---|---|
permlink | re-amosbastian-re-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t153137951z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-21 15:31:39 |
last_update | 2018-01-21 15:31:39 |
depth | 3 |
children | 0 |
last_payout | 2018-01-28 15:31:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 29 |
author_reputation | 913,538,372 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 31,132,921 |
net_rshares | 0 |
I love how quick you are! @amosbastian will be going over your code tomorrow
author | juliank |
---|---|
permlink | re-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t213639568z |
category | contest |
json_metadata | {"tags":["contest"],"users":["amosbastian"],"app":"steemit/0.1"} |
created | 2018-01-20 21:36:39 |
last_update | 2018-01-20 21:36:39 |
depth | 2 |
children | 0 |
last_payout | 2018-01-27 21:36:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 76 |
author_reputation | 117,823,071,447,502 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,956,878 |
net_rshares | 0 |
I think you need to take the user's current vote power into account, too
author | maxg |
---|---|
permlink | re-luj1-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t205029873z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-20 20:50:30 |
last_update | 2018-01-20 20:50:30 |
depth | 2 |
children | 0 |
last_payout | 2018-01-27 20:50:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 72 |
author_reputation | 5,859,582,764,121 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,949,626 |
net_rshares | 0 |
Code: https://gist.github.com/maxwellgerber/f6b8cfd861228e28f8a57f8887e3a0e8
author | maxg |
---|---|
permlink | re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t204958942z |
category | contest |
json_metadata | {"tags":["contest"],"links":["https://gist.github.com/maxwellgerber/f6b8cfd861228e28f8a57f8887e3a0e8"],"app":"steemit/0.1"} |
created | 2018-01-20 20:49:57 |
last_update | 2018-01-20 20:49:57 |
depth | 1 |
children | 5 |
last_payout | 2018-01-27 20:49:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.150 HBD |
curator_payout_value | 0.036 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 76 |
author_reputation | 5,859,582,764,121 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,949,539 |
net_rshares | 16,684,236,538 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
juliank | 0 | 13,782,217,442 | 1% | ||
veenox | 0 | 171,016,619 | 100% | ||
steempytutorials | 0 | 2,731,002,477 | 100% |
Just tested it and there are some tiny errors, but if you fix them, then it works as specified! Go, go, go, if you are quick you can still win!
author | amosbastian |
---|---|
permlink | re-maxg-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t140830906z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-21 14:08:30 |
last_update | 2018-01-21 14:11:18 |
depth | 2 |
children | 3 |
last_payout | 2018-01-28 14:08:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 143 |
author_reputation | 174,473,586,900,705 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 31,114,994 |
net_rshares | 0 |
😇
author | emrebeyler |
---|---|
permlink | re-amosbastian-re-maxg-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t142713754z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-21 14:27:12 |
last_update | 2018-01-21 14:27:12 |
depth | 3 |
children | 0 |
last_payout | 2018-01-28 14:27:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.048 HBD |
curator_payout_value | 0.012 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1 |
author_reputation | 448,535,049,068,622 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 31,119,215 |
net_rshares | 5,341,674,648 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
turbot | 0 | 5,341,674,648 | 100% |
Cleaned and updated! There was one pretty big error with how I was calculating voting power. The voting power param set on the account object is your VP at the last time you voted. So you need to do some math with the last vote time to figure out your current real voting power. ``` def calc_vote_power(account): vp = account['voting_power'] last = datetime.strptime(account['last_vote_time'], "%Y-%m-%dT%H:%M:%S") diff = datetime.utcnow().timestamp() - last.timestamp() return (vp + 1e4 * diff / 432e3) / 10000 ``` I actually had to find this one by going through the source code for [steemnow](https://www.steemnow.com/@maxg)  Other than that it was just import errors and the like :P
author | maxg |
---|---|
permlink | re-amosbastian-re-maxg-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180121t164425662z |
category | contest |
json_metadata | {"tags":["contest"],"image":["https://steemitimages.com/DQmZF75n9KMfq6sjwQ385bvk4DZQtezCW3kvBBs2f5A1kkt/image.png"],"links":["https://www.steemnow.com/@maxg"],"app":"steemit/0.1"} |
created | 2018-01-21 16:44:24 |
last_update | 2018-01-21 16:44:24 |
depth | 3 |
children | 1 |
last_payout | 2018-01-28 16:44:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.054 HBD |
curator_payout_value | 0.018 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 790 |
author_reputation | 5,859,582,764,121 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 31,148,541 |
net_rshares | 6,821,979,169 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
amosbastian | 0 | 6,821,979,169 | 100% |
Again on point! Just about to go over the code from the challenge from yesterday and you have already submitted another ;)
author | juliank |
---|---|
permlink | re-maxg-re-steempytutorials-daily-steem-python-challenge-8-win-1-steem-20180120t213722734z |
category | contest |
json_metadata | {"tags":["contest"],"app":"steemit/0.1"} |
created | 2018-01-20 21:37:21 |
last_update | 2018-01-20 21:37:21 |
depth | 2 |
children | 0 |
last_payout | 2018-01-27 21:37:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 122 |
author_reputation | 117,823,071,447,502 |
root_title | "Daily Steem-Python Challenge #8, Win 1 Steem!" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 30,956,990 |
net_rshares | 749,512,889 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
maxg | 0 | 749,512,889 | 100% |