My contest results and automatizing contests with steem-python!
I made a simple contest 5 days ago to celebrate my milestone of 100 followers. Since I have a trip to Ukraine tomorrow, I had to make the draw today.
Contest had two simple rules.
- Upvote the post
- Follow my account
I want to make this post also educational about the steem blockchain. So, I will share how I make the contest.
Getting voters list
Assuming that you have steem-python installed in your local environment, let's get the post details.
steem-python package has a class named Post. This includes all the stuff related with posts.
Let's get my contest post.
from steem.post import Post
post = Post('emrebeyler/100th-follower-milestone-sbd-giveaway-5-sbd-prize-pool')
Post object has some properties/methods inside. active_voters is something we can use to get the voter list. But taking the list is not enough, also I want to enumerate them and dump list into a text file so I can use random.org to select a number and match with the winners. Also I need to check each voter that if they follow me or not.
Let's get the voters list:
voters = [p.get("voter") for p in p.active_votes]
I need to know they follow me or not. Let's check it. To get the follower list of an account, we can use Account object in the steem-python.
account = Account('emrebeyler', Steem())
account.get_followers()
What I need now, is to find the intersection of my follower list and post upvoters. Python has a built-in type as set, which has a .intersection method. Let's use it.
This one-liner is what I need.
participants = set(account.get_followers()).intersection(set(voters))
Now I have the participant list. Most of the work is done, let's write them into a text file with numbers.
f = open ("/tmp/list.txt", "w+")
for index, voter in enumerate(participiants):
f.write("%s - %s\n" % (index + 1, voter))
f.close()
All set!
After that point, I just went to random.org and get 3 random integers.
Congrats. @nickperry, @omersurer, @mahmutfirat. I will send your prizes in 5 minutes. Check your wallet.
Thanks to all my followers and participants. See you next time.
For turkish visitors;
Yüzüncü takipçim şerefine bir yarışma düzenlemiştim. Aylar öncesinden planlı Lviv gezimi unuttuğum için bugünden çekilişi yapmak durumunda kaldım. Oy verenlerin listesini alma, beni takip ediyorlar mı kontrolünü yapma gibi işlerini yine benim çılgın siyah konsolumdan yaparken, aslında bunu da öğretici bir şekilde yapabilirim belki diye, ingilizce kısmında nasıl yapıldığını anlattım.
Kazananlar @nickperry, @omersurer, @mahmutfirat oldu. Ödüllerini birazdan yollayacağım. Başka yarışmalarda görüşmek üzere!





iyi yolculuklar
img credz: pixabay.com
Nice, you got a 71.0% @welcomebot upgoat, thanks to @emrebeyler
Want a boost? Minnowbooster's got your back!
The @OriginalWorks bot has determined this post by @emrebeyler to be original material and upvoted(2%) it!
To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
Thanks for the intro to the API! I was just about to go looking for this kind of content, so it was handy that it was already waiting for me in my feed :-)
If I could make a few suggestions on some alternative ways of doing some pieces of this...
Instead of using random.org or even writing it out to a file:
Or, if you really do want to write it out to a file, instead of manually calling the close operation on the file handle, I highly recommend the
withblock. It will make sure close gets called, even when there's an error and it also means shorter code (by a tiny bit), here's your block re-written to usewith:glad to hear post is helpful for you.
I have announced that I will use random.org in the contest so I used it. regarding context manager usage, you're right. it's a better practice.
Thanks.
guzel resımlerı bklıyoruz
great post. statics are super cool.
thank you! :)
This post has received a 2.25 % upvote from @booster thanks to: @emrebeyler.
Great post thankyou.
I'm just getting started on this and your post is very helpful.
Thanks
Tesekkurler @emrebeyler ve iyi yolculuklar. Bize Lviv'den guzel fotograflar paylasmayi unutma :)
bakalım, vakit bulabilirsem paylaşacağım. :)
This wonderful post has received a bellyrub 5.04 % upvote from @bellyrub.
This post has received a 5.14 % upvote from @buildawhale thanks to: @emrebeyler. Send at least 1 SBD to @buildawhale with a post link in the memo field for a portion of the next vote.
To support our daily curation initiative, please vote on my owner, @themarkymark, as a Steem Witness