Creating a follow a follower script using python #2.5 (code tidy up)

in #steemit7 years ago

Follow a follower using Python #25.jpg
Hi Steemers,

This follows on from part 2 [see below for links] where I’m attempting to create a simple script that would list my followers and if I wasn’t following then print the names to the shell and then automatically follow them.
To recap the flow I’m working to is:

  1. Create a list of my follower account names
  2. Create a list of account names of all the people I’m following
  3. Check to see if the follower is on the following list if not:
    a. Print the account name to the shell
    b. Automatically follow the account

So far I have managed to:
· get steem installed – this took far longer than I expected (due to my incompetence)
· have successfully got to print to the shell a list of my followers

Oh and to make things even more fun I thought I would do this using a Raspberry Pi 2 as we had one sitting around not doing much!

I have split this into 3.5 parts/posts as it got a bit long for an all in one:
· part 1 getting a list of my followers,
· part 2 getting a list of who I’m following
· part 2.5 not really a part just a bit of code tidying up - this post
· part 3 comparing lists and following

All I have done now is create some functions to make the code a little easier to read and use

# Import Statements
import time
from steem import Steem

# Variables
steem = Steem()
account = 'garethdear'

# Function - get count of followers
def get_my_followers():
    followerCount = steem.get_follow_count(account)['follower_count']
    return followerCount

# Function - get count of following
def get_my_following():
    followingCount = steem.get_follow_count(account)['following_count']
    return followingCount

# Function - get a list of my followers
def get_my_followers_list():
    print ("Getting my followers")
    followers = []
    followersStart = 0
    while followerCount > 0:
        tempFollowers = steem.get_followers(account, followersStart, 'blog', 100)
        if (followerCount > 100):
            followersStart = tempFollowers[99]['follower']
            del tempFollowers[99]
        followers.extend(tempFollowers)
        followerCount -=100

    myFollowerNameList = []
    for aFollower in followers:
        name1 = aFollower['follower']
        myFollowerNameList.append(name1)

    return myFollowerNameList

# Function - get a list of who I'm following
def get_my_following_List():
    print ("Getting my following")
    following = []
    followingStart = 0
    while followingCount > 0:
        tempFollowing = steem.get_following(account, followingStart, 'blog', 100)
        if (followingCount > 100):
            followingStart = tempFollowing[99]['following']
            del tempFollowing[99]
        following.extend(tempFollowing)
        followingCount -=100

    myFollowingNameList = []
    for aFollower in following:
        name2 = aFollower['following']
        myFollowingNameList.append(name2)

    return myFollowingNameList

#Get the counts of followers and following
followerCount = get_my_followers()      #Get the count of followers
followingCount = get_my_following()     #Get the count of following

#Get the accounts in the lists
follower_names = get_my_followers_list()    #Get the names of my followers
following_names = get_my_following_List()   #Get the names of who is following me
  
#Print out the names
for name in follower_names:
    print(name)
for name in following_names:
    print(name)

Hooray! – Stage 2.5 complete now onto stage 3
I’ll post this in a day or so

Please bear in mind that I am still a newbie to python and there will be many other (and much more elegant) ways of coding this.

Have fun and bye for now
Gareth

Part one: https://steemit.com/steem/@garethdear/creating-a-follow-a-follower-script-using-python-1-followers

Part two - https://steemit.com/steemit/@garethdear/creating-a-follow-a-follower-script-using-python-2-following

Sort:  

This post deserve a upvote..plz visit my page also today I post some interesting content they are waiting for your your upvote.

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.029
BTC 57971.70
ETH 2448.51
USDT 1.00
SBD 2.34