Steemit-Python-Bot | Part 3: Relike someones post if they liked yours

in #utopian-io7 years ago (edited)

Dress to Kill.png

<h4>What Will I Learn? <ul> <li>How to upvote a post <li>How to build a basic bot <h4>Requirements <ul> <li>Python 3.6 <li>steem-python <p dir="auto">(I personally use Windows and it was quite challenging to install the library but this <a href="https://steemit.com/utopian-io/@holger80/how-to-install-steem-python-for-windows" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">tutorial helped me a lot. <h4>Difficulty <ul> <li>Beginner <h4>Tutorial Contents <h5>1. Setup <p dir="auto">We first need to import some necessary librarys and set up a variable (we need it later). <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701743/tldg0wh92y6iint6jlha.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701743/tldg0wh92y6iint6jlha.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701743/tldg0wh92y6iint6jlha.png 2x" /> <p dir="auto">Obviously, we need to specify a node to connect to.<br /> Then you need to change <code> account to your own account name and add your <code> private posting key and your <code> private active key in order to be able to upvote later. <p dir="auto">With this information set, we can finally initialize the steem class. <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701881/kd7t3gg0b2dflt5eqgmw.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701881/kd7t3gg0b2dflt5eqgmw.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517701881/kd7t3gg0b2dflt5eqgmw.png 2x" /> <h5>2. <code> relike() <p dir="auto">(The first two functions we use are explained in detail in my <a href="https://steemit.com/utopian-io/@wil1liam/steemit-python-bot-or-part-1-how-to-find-someone-s-newest-post" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">last two tutorials) <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704993/erkrexfdvpyxisbtl6ui.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704993/erkrexfdvpyxisbtl6ui.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704993/erkrexfdvpyxisbtl6ui.png 2x" /> <p dir="auto">In the beginning, we need to know what our newest post is and therefore we input our username in the <code> get_newest_post function, which returns the "post identifier" of our post ( Author + Permalink). <p dir="auto">Now we can build on top of that and get a list of the users who upvoted our post with the <code> get_voter function. <p dir="auto">Finally we just pass this list into our new <code> upvote_newest_post function and it will upvote their posts. <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517703246/fq8wkd00grdsrpmfx5qa.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517703246/fq8wkd00grdsrpmfx5qa.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517703246/fq8wkd00grdsrpmfx5qa.png 2x" /> <h5>3. <code>upvote_newest_post() <p dir="auto">Because the upvote function of the python-steem library needs your account-name we need to pass it into the function. Secondly, we need the "post identifier" to know what post to upvote. <p dir="auto">This function will basically just go over every entry in the list of people who upvoted our post and finds their newest posts and then upvotes them. <p dir="auto">To do this we start with a for loop : <code> for i in usernames and then <code> get_newest_post(i) ( get the newest post for every entry in the list). <p dir="auto">In the end, we just <code>try to upvote the post and if this fails ( we already upvoted this post ) we will <code> except this error and just continue running the script. <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704006/nmwfpcnvfdjdhljmc2zp.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704006/nmwfpcnvfdjdhljmc2zp.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704006/nmwfpcnvfdjdhljmc2zp.png 2x" /> <p dir="auto">As you can see I set <code> weight to 100: this means that you will upvote the post with 100% voting power. You can of course change this number if you wish. <p dir="auto">( If your weight is -100 you will downvote the post -- please don't do that :) ) <h5>3. <code>main loop <p dir="auto">To let the bot run infinitely we make a <code> while(1) loop. ( 1 == always true ) <p dir="auto">Because I personally had problems with the bot stopping I added one line which debugs the time to let you know if it's still running.<br /> Now just execute the <code>relike function with your account name as the one and only input. <p dir="auto">Because it is unnecessary to execute this code every second [ it will put load on the API --> slows other people down :( ] I let it execute every 5 minutes. <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704761/e1qdmatvclzdvdddyqj9.png" alt="image.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704761/e1qdmatvclzdvdddyqj9.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1517704761/e1qdmatvclzdvdddyqj9.png 2x" /> <h2><a href="https://github.com/ko-redtruck/steemit-relike-bot" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Complete Code on Github <h4>Curriculum <ul> <li><a href="https://utopian.io/utopian-io/@wil1liam/steemit-python-bot-or-part-1-how-to-find-someone-s-newest-post" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Part 1: How to find someone's newest post <li><a href="https://steemit.com/utopian-io/@wil1liam/steemit-python-bot-or-part-2-how-to-return-a-list-of-the-people-who-upvoted-your-post" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Part 2: How to return a list of the people who upvoted your post <p dir="auto"><br /><hr /><em>Posted on <a href="https://utopian.io/utopian-io/@wil1liam/steemit-python-bot-or-part-3-relike-someones-post-if-they-liked-yours" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian.io - Rewarding Open Source Contributors<hr /><p>
Sort:  

Post helpful, I like

Your Post Has Been Featured on @Resteemable!
Feature any Steemit post using resteemit.com!
How It Works:
1. Take Any Steemit URL
2. Erase https://
3. Type re
Get Featured Instantly – Featured Posts are voted every 2.4hrs
Join the Curation Team Here | Vote Resteemable for Witness

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @wil1liam I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Hello, you received a boost courtesy of @steemdunk! Steem Dunk is an automated curation platform that is easy and free for use by everyone. Need an instant boost? Send 0.200 SBD with your full post url as the memo to @steemdunk for an upvote. Join us at https://steemdunk.xyz

Upvote this comment to support the bot and increase your future rewards!