So you're hosting a competition, you're looking for a way to announce a random winner that fits a certain criteria and maybe you feel like getting to know the Steem-Python library a little better too. Well look no further. I'll be starting a new tutorial series called "Steem-Python Beginner Series" where I'll be going through a few methods in the steem-python library each time and show you how to use them and how you can apply them in your own scripts. As always, in order to use this script you need to have the steem-python library installed which you can get by running the following command: pip install steem
. You'll also need to be running at least Python version 3.5 to use the library and have pip installed to run the above command.

Badly photoshopped image. original
Today I'll be using the following methods from the library:
get_active_votes()
get_reblogged()
get_followers()
In this example I'll be sharing a little script I wrote that you can use to find a winner in a competition you're hosting on Steemit. So lets say your competition rules are that everyone should upvote your post, resteem your post as well as follow you and that you will be picking a random lucky winner to win some money or whatever you feel like giving away. The following script will retrieve all the people who voted on your post, all the people who reblogged your post and all the people currently following you. The script then creates a list of all potential winners who fit the criteria and picks a random winner. You can copy this script or get it on my GitHub.
from steem import Steem
import random
#create steem instance
s = Steem()
#set your username
#my username as example
user = 'benniebanana'
#set the link to your post
#my previous post for example
postLink = 'getting-started-with-steem-python-upvote-and-comment-bot-examples-linux'
#get all the people who voted on the post
voters = s.get_active_votes(user, postLink)
#create a list of all the voters
voterList = [user['voter'] for user in voters]
#get a list of all the people who reblogged the post
reblogs = s.get_reblogged_by(user, postLink)
#get of your follower count
followerCount = s.get_follow_count(user)['follower_count']
#retrieve all your followers names
followers = s.get_followers(user, 0, 'blog', followerCount)
#create a list of all your followers
followerList = [follower['follower'] for follower in followers]
#create a list of all the people who voted, reblogged and followed you
potentialWinnerList = []
for potentialWinner in voterList:
if potentialWinner in reblogs and potentialWinner in followerList:
#user is following us and reblogged our post so lets add them to the list
potentialWinnerList.append(potentialWinner)
#pick a random winner from the list
#check if our list is empty
if not potentialWinnerList:
#our list is empty :(
print("No winners :( The list is empty")
else:
#we have some potential winners so lets pick a random one
winner = random.choice(potentialWinnerList)
print("yaaay "+winner+" won the competition!!!")