Introduction
Recently, I saw more and more people giving away SBD oder ETH for their followers, who commented on their post. I’m not aware of any solution to automate such a process and therefore I created a simple script to do so.
What Will I Learn?
- How to get ALL comments from a post
- How to choose a random winner from your comments
- How to get the most upvoted comment
- How to send SBD/STEEM
Requirements
- Python 3.6
- Steemit-Python
Difficulty
- Basic
Tutorial Contents
Basic Setup
Obviously, we need to import steem
first but to choose a random winner we also have to import the built-in library random
. Then we need to set the node
, include our private posting key and our private active key in order to send SBD/STEEM later and finally need to initialize the Steem Class
.
Having finished the basic stuff, we should start getting the comments from our post. Because we do not want to change the url in the code every time using the script, I decided to ask for a user input.
get_all_comments()
Getting all comments may seem simple, however if we just use the simple function s.get_content_replies(account,post_identifier)
, we will not get all comments, any sub-comment will not be included…. With the help of a for loop
we can get the replies of every comment under our post. The children
element will tell us how many replies a comment has.
Now we simply add these new comments to our list of the original comments and return it. We are done with our first function.
random_winner()
Let us continue with choosing a random winner. This is actually the most straightforward function but we still want to prevent abuse by users posting a lot of comments. So no matter how many comments you write your chance always stays the same. To achieve this we create an empty list in which we will save all commentators and choose a random winner from that. Using a for loop
and an if statement
we will go through every comment and add the commentator to the list if he isn’t included already. Then we use the function random.randrange(length(commentators_list))
to return a random number and finally just return the entry of this number from the commentators list...
community_winner()
Now we want to get the comment who got the most upvotes. You may think this is the first comment under each post but that’s only the comment with the highest payout. Because, in this case I want every upvote to be weighted equally we will use the net_votes
of the comment.
Usually the first comment will be the one with the most upvotes, so we simply set it as our top comment but to make sure we will go through all comments again and check if they have more upvotes. If one of them has more we set it as our new top comment and continue through our list of comments…
Finally, we only need to return the author of the top comment.
reward_winners()
For transferring funds on the Steem Blockchain we can use this command: transfer(to, amount, asset, memo='', account=your_account)
. I only created an extra function to simplify the process of sending the funds…
We will need a for loop
to go through the list of our winners and send the funds for each winner. In addition, I created a few variables: asset (SBD/STEEM), reward_pool, memo for the random winner, memo for the community winner and a list including all the before created memos. Each winner will get an equal amount of SBD/STEEM: 1 / length(winners_list) * reward_pool
.
Furthermore, every winner we will receive a different memo from our lists of memos. To know which memo to use we will use the i
of the for loop in range(length(winners))
. If we only have a list of 2 winners, i
will be 0 and then 1. If you have three winners or more, please make sure to have a list of memos of the same length and that the memos are arranged in the same order as the list of the winners.
To be fair, it would require less lines of code for only 2 winners, if we just wrote the transfer part without any functions...
main programm
Now we have written all functions but we will still need to execute them. First of all, let us set the variable comments
to our function get_all_comments()
and use the url as an input.
Secondly, we need to get our winners with the previous functions and create a list with the returned value of each function.
As the last step in the tutorial, we will need to send the rewards. I prefer to print the returning value of this function to determine if the money was sent.
Final Code (Github.com)
Curriculum
Steemit Python Bots
- Part 1: How to find someone's newest post
- Part 2: How to return a list of the people who upvoted your post
- Part 3: Relike someones post if they liked yours
Steemit Python Analysis
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I am not being able to get steem-python installed in my laptop :(
It's great to see you developing tools using steem-python :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
a few days ago I also struggled really hard to install it on my raspberry pi 3 ...
git clone https://github.com/steemit/steem-python.git
cd steem-python
pipenv install --three --dev # use --two instead of --three for Python 2.7
pipenv install .
I think this someone worked in the end but on my main windows machine I used a tutorial by @holger80.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks for pointing me to @holger80, it helped :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This is a great tutorial. I learnt something new as a beginner in python. To prevent abuse we can just check if it's already in the list.
I use STEEM piston but I may start learning STEEMIT-Python for fun.
Thanks a lot @wil1liam, well deserved upvotes ;)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great article. I'm going to have to try to do this one day.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Awesome
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by ReD_TrucK from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Greetings! I am a minnow exclusive bot that gives a 5X upvote! I recommend this amazing guide on how to be a steemit rockstar! I was made by @EarthNation to make Steemit easier and more rewarding for minnows.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @wil1liam I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
great tut man!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit