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

in #utopian-io7 years ago (edited)

Dress to Kill.png

What Will I Learn?

  • How to upvote a post
  • How to build a basic bot

Requirements

  • Python 3.6
  • steem-python

(I personally use Windows and it was quite challenging to install the library but this tutorial helped me a lot.

Difficulty

  • Beginner

Tutorial Contents

1. Setup

We first need to import some necessary librarys and set up a variable (we need it later).

image.png

Obviously, we need to specify a node to connect to.
Then you need to change account to your own account name and add your private posting key and your private active key in order to be able to upvote later.

With this information set, we can finally initialize the steem class.

image.png

2. relike()

(The first two functions we use are explained in detail in my last two tutorials)

image.png

In the beginning, we need to know what our newest post is and therefore we input our username in the get_newest_post function, which returns the "post identifier" of our post ( Author + Permalink).

Now we can build on top of that and get a list of the users who upvoted our post with the get_voter function.

Finally we just pass this list into our new upvote_newest_post function and it will upvote their posts.

image.png

3. upvote_newest_post()

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.

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.

To do this we start with a for loop : for i in usernames and then get_newest_post(i) ( get the newest post for every entry in the list).

In the end, we just try to upvote the post and if this fails ( we already upvoted this post ) we will except this error and just continue running the script.

image.png

As you can see I set 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.

( If your weight is -100 you will downvote the post -- please don't do that :) )

3. main loop

To let the bot run infinitely we make a while(1) loop. ( 1 == always true )

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.
Now just execute the relike function with your account name as the one and only input.

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.

image.png

Complete Code on Github

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

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!