Pick a Winner with @dorabot - Steem-Python in Action
Interacting with @dorabot on Steemit
One of @dorabot’s features is to pick a winner from users who upvoted a post or a comment.
This can be used as part of a contest or as a way to pick a visitor for a reward giveaway.
This feature has been available on the PALnet Discord server and can be used link this:
?winner steemit-URL
Please see an example below:
If the URL is a post, @dorabot will pick a winner from the upvotes, but will also take re-steems and followers into account. For example:
- Only upvote = 1 chance to win
- Post re-steem or author follower = 1 extra chance to win
- Post re-steem + author follower = 2 extra chances to win
In case you don't know how to get the URL of a comment, click the time indicator as shown below:
The initial idea for this feature came from a post from @benniebanana.
The original code only picked a winner if the user had upvoted, re-steemed and followed the author. I modified this part to make it work in the way I have described above.
I also modified the code to make it work on comments and not only posts.
Another modification was linked to a limitation in the “get_followers” function where only a max 1000 users could be retrieved. I modified that to take into account an “infinite” amount of followers.
I have now made this feature available directly on Steemit as well. Include the two words “@dorabot ?winner” in any comment and Dorabot will reply back with the winner. You don’t need to strictly use only these two words, see the example below.
@digitalking has been a great test user and was very keen to try this out on his various Steemit contests. See below for his first attempt to use @dorabot to pick a lucky winner. Please check out this link.
This is the only feature part of Dorabot available on Steemit at this moment. I want to avoid making her a spam bot, but for this function I think it makes much sense.
Below is the full python code for the function that will pick a winner. You call it with any Steemit URL and it will return the Steemit username of the winner. I call this function from a wrapper that listens to the Steemit stream for the words "@dorabot ?winner", and then replies back with the winner.
#call function with a Steemit URL in a string variable
def getwinner(url:str):
#create steem and post instance
my_nodes = ['https://gtg.steem.house:8090', 'https://steemd.minnowsupportproject.org']
s = Steem(nodes=my_nodes)
p = Post(url, s)
comment = 1 #1 = comment, 0 = post
followerList = [] #initiate empty list to store followers
#store the post/comment author
user = p.author
#get all the people who upvoted
voters = s.get_active_votes(user, p.permlink)
#extract the names of all the voters
voterList = [user['voter'] for user in voters]
#In case of self upvote, remove the author from the list
if user in voterList:
voterList.remove(user)
#get a list of all the people who reblogged the post
reblogs = s.get_reblogged_by(user, p.permlink)
#is the author in the reblogged list
if user in reblogs:
#then this is not a comment
comment = 0
#remove the author from the reblogged list
reblogs.remove(user)
#Only collect followers if it is a post, not a comment
if(comment == 0):
#get the author's follower count
followerCount = s.get_follow_count(user)['follower_count']
#initiate variable used to retrieve all followers
followers = []
followerStart = 0
#loop is needed to handle values larger than 1000
while followerCount > 0:
#get up to 1000 followers
temp = s.get_followers(user, followerStart, 'blog', 1000)
if (followerCount > 1000):
#set Nr.1000 follower as the start point in the next iteration
followerStart = temp[999]['follower']
#delete Nr.1000 as it will be added in the next iteration
del temp[999]
followers.extend(temp)
followerCount -= 1000
#create a list with the names of all followers
followerList = [follower['follower'] for follower in followers]
#initiate a list to combine all people who voted, reblogged and followed
potentialWinnerList = []
#loop through all people who voted
for potentialWinner in voterList:
#Add everyone who voted as a potential winner.
potentialWinnerList.append(potentialWinner)
if potentialWinner in followerList:
#user is following us as well. This will give them another chance.
potentialWinnerList.append(potentialWinner)
if potentialWinner in reblogs:
#user reblogged our post as well. This will give them yet another chance.
potentialWinnerList.append(potentialWinner)
#pick a random winner from the list
#check if our list is empty
if not potentialWinnerList:
#our list is empty :(
return None
else:
#we have some potential winners so lets pick a random one
winner = random.choice(potentialWinnerList)
return(winner)
Thank you for reading!
Stayed tune for future updates.
Please let me know if you have any questions.
Click HERE to connect to MSP's Discord server.
I had the chance to test the @dorabot in the first stages of its developement and use it in 2 of my contests.
FUNNY CONTEST #1 and FUNNY CONTEST #2
In fact i made these "funny" contests to test the functionality of the @dorabot, in order to be sure that i can use it in future contests that require a random winner to be picked. @danielsaori was very helpful during the process to pick the winners and i want to thank him for that.
The ?winner command that picks randomly a winner from the voters list (post or comment) and can be executed directly in the comments section of a post, is something that was missing from the steemit platform. I had see many contests in steemit that was picking a random winner with the use of third party services.
With the use of dorabot its very easy for everyone to think and create contest posts and then pick the winners randomly. And having the "randomly" defined in this post, is crystal clear how the @dorabot picks the winner.
Thanks to @danielsaori for his effort to create this tool and for making it available to everyone for free.
The winner is: dorabot!!!
Naughty girl! Should probably exclude the option of picking herself as the winner 😀
@dorabot ?winner test
The winner is: digitalking!!!
@dorabot ?winner testing
The winner is: dorabot!!!
Plz try to declare winner...I am eager to see who is the winner??😊😊😊
Yes, I will publish it today. Sorry, but I have been a bit lazy around steemit lately. 😊
Hope that You will publish within Quick time
Right, now it is out!
Not super fast, but at least within 24 hours from my comment above. ;)
Hi @danielsaori, when you will do comments challenge again? It really helped me in learning to write sentence to sentences in my post. Sorry if this comment is not in accordance with this post.
Hello! I will try to get the winner's post out tomorrow and then start a new one in a few days. See you in the next round. :)
Okay, i am waiting :
Sorry, but I have been really busy and Steemit lazy lately... :)
Will publish the winner today and then have the new post out in a couple of days.
New contest is out in case you missed.
Currently 35SBD is in the pot!
Here is a small test for @dorabot.
Please show me the ?winner
The winner is: abdlhakim!!!
Well done @dorabot!! :)
Does ?winner work on comments as well?
The winner is: danielsaori!!!
@dorabot ?winner
The winner is: danielsaori!!!
The winner is: danielsaori!!!
The winner is: danielsaori!!!
img credz: pixabay.com
Nice, you got a 99.0% @mamqmuqit upgoat, thanks to @danielsaori
It consists of $5.53 vote and $1.84 curation
Want a boost? Minnowbooster's got your back!
The @OriginalWorks bot has determined this post by @danielsaori to be original material and upvoted(1.5%) it!
To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
Testing a little... !curate
Testing a little more... !curate
!curate