Simple working code to be prompt an unfollow of anyone not following you – using Tweepy

Source code credit given to http://www.dototot.com/write-twitter-bot-python-tweepy-unfollow-non-followers-command-line/

 

I’m modified the code to be simple and all in a single file for those that are not as developer savvy

 

Tweepy is available here https://github.com/tweepy/tweepy

 

Once you have the Tweepy API installed and working the following code works flawlessly and is very simple

 

———————————————————————-

import tweepy

 

 

#Twitter API credentials

 

screen_name = “”  # Place your username inside “”

 

consumer_key = “” # your info to be inserted

 

consumer_secret = “” # your info to be inserted

 

access_key = “” # your info to be inserted

 

access_secret = “” # your info to be inserted

 

 

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

auth.set_access_token(access_key, access_secret)

api = tweepy.API(auth)

   

followers = api.followers_ids(screen_name)

friends = api.friends_ids(screen_name)

 

for f in friends:

    if f not in followers:

        print “Unfollow {0}?”.format(api.get_user(f).screen_name)

        if raw_input(“Y/N?”) == ‘y’ or ‘Y’:

            api.destroy_friendship(f)

 

——————————————————————————————————————————————

UnFollow_Tweepy

Leave a Reply

Your email address will not be published. Required fields are marked *