Simple script to follow back your followers / An automatic following ROBOT by @chinadaily

in #steemdev7 years ago (edited)

Introduction

As we begin writing on SteemIT, we are gaining more and more attention.
Some loyal users also followed us to show our articles in their home page.
Out of courtesy, I think it's important that we follow our followers back.
But manual handling is too much trouble, especially when the quantity of followers is large.
So I tried to use scripts to process it automatically, finally I realized this goal.

Now, let me share it with you.

5-Tips-to-Follow-if-You-Create-a-Website-for-Free.jpg

(Image source: 5-Tips-to-Follow-if-You-Create-a-Website-for-Free

Preparation

We need to do some preparations to run the script.

  • Install official Python STEEM library
  • Find & Import posting private key

We had already introduced them in our previous article.
To find more details, go to the following link:

Detailed steps and function

In order to achieve the goal, we need to do following things in our scripts

  • A. Find out the followers of my account.
  • B. Find out the accounts(following) I followed.
  • C. Find out the account followed me but I don't followed
  • D. Followed the account we funded in above step

The official Python STEEM library provide the APIs to finish steps A, B, D

  • get_followers(account: str, start_follower: str, follow_type: str, limit: int)
  • get_following(account: str, start_follower: str, follow_type: str, limit: int)
  • follow(follow, what=['blog'], account=None)

The script

Here is the simple script to follow back your followers:

#!/usr/bin/env python
import sys
import time
from steem import Steem

account = 'chinadaily'

def get_followers(account, steem):

        list = []
        offset = ''
        while True:
                temp = steem.get_followers(account, offset, 'blog', 100)
                if (len(temp) < 100):
                        list += temp
                        break

                offset = temp.pop()['follower']
                list += temp

        followers = [x['follower'] for x in list]
        return followers

def get_following(account, steem):

        list = []
        offset = ''
        while True:
                temp = steem.get_following(account, offset, 'blog', 100)
                if (len(temp) < 100):
                        list += temp
                        break

                offset = temp.pop()['following']
                list += temp

        following = [x['following'] for x in list]
        return following


def main(argv=None):

        steem=Steem()

        followers = get_followers(account, steem)
        following = get_following(account, steem)
        print('Followers: {}'.format(len(followers)))
        print('Following: {}'.format(len(following)))
        print(followers)
        print(following)

        for f in followers:
                if f not in following:
                        try:
                                steem.follow(f, what=['blog'], account = account)
                                print('Follow ({}) successfully!'.format(f))
                                time.sleep(30)
                        except Exception as e:
                                print(e)

if __name__ == "__main__":
        sys.exit(main())

Follow back your followers by command

Save the above script as auto_follow.py.
Now, you can follow back your followers by command
python auto_follow.py
You may be prompt to input wallet password, input it and continue...
The scripts works well for me.

Run script automatically

You can run the scripts automatically in desired period ( such as per week) by set up cron.
To avoid input password manually, you can add
steem.wallet.unlock(pwd = 'yourpassword')
After created steem instance.

And In my previous article, @furion provide a better method, many thanks to him:
By setting the environment variable UNLOCK with your python-steem wallet password, you can avoid unlocking logic or pw handling in your code.

For other purposes

By simply editing it, you can use this script in other purposes easily.
For example,

  • To follow the accounts other one followed.
  • To follow the accounts who have higher reputation.
  • Others ...

Previous Articles

Sort:  

One line in this code really helped me.. thanks ;)

Loading...

Steem module will not load are you aware of this? Perhaps it's just me but I can not make it work

Follow me
I'll follow you back:)

This post is highly informative, keep it up

Thanks for this guide. It helped me a lot. ^_^

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63099.62
ETH 2555.59
USDT 1.00
SBD 2.83