Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Last active July 16, 2023 07:11
Show Gist options
  • Save nickleefly/e9d084bc03346e882487b627b4ac9396 to your computer and use it in GitHub Desktop.
Save nickleefly/e9d084bc03346e882487b627b4ac9396 to your computer and use it in GitHub Desktop.
remove matching twitter followers

README

  • This script will check each of the user from user_list if the user in the followers_list it will remove the user from your followers

  • For that first it will block the matching user one by one and then unblock them. If you are following your matching followers, you won't be subscribed to them anymore once you run this job.

  • Install tweepy module using pip. To install tweepy run below command in your terminal.

  • pip install tweepy

  • Please replace consumer_key and consumer_secret. Visit https://apps.twitter.com to get your consumer_key and consumer_secret.

  • Once you generate consumer key create an access token from same twitter page. Replace access_token and access_token_secret with provided values. Then run the script.

import tweepy
consumer_key = '<consumer_key>'
consumer_secret = '<consumer_secret>'
access_token = '<access_token>'
access_token_secret = '<access_token_secret>'
author = 'my_twitter_user_name'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
followers = []
for page in tweepy.Cursor(api.get_follower_ids, screen_name=author).pages():
followers.extend(page)
user_list = ['a', 'b', 'c', 'd']
for user in user_list:
if user in followers:
api.create_block(user)
api.destroy_block(user)
print(user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment