Created
November 14, 2020 12:29
-
-
Save wapcrazut/c1e8205e366166acd0a7af15a18946e7 to your computer and use it in GitHub Desktop.
Tweepy - Unfollow people don't follow you back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Based on Jamieson Becker's unfollow script http://pastebin.com/CxUDMtMi | |
# Python 3 compatible. | |
import time | |
import tweepy | |
import sys | |
auth = tweepy.auth.OAuthHandler( | |
consumer_key='APITOKEN', | |
consumer_secret='APITOKEN_SECRET') | |
auth.set_access_token( | |
'ACCESS_TOKEN', | |
'ACCESS_TOKEN_SECRET') | |
api = tweepy.API(auth_handler=auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) | |
print("Loading followers..") | |
followers = api.followers_ids("USERNAME") | |
print("Found %s followers, finding friends.." % len(followers)) | |
following = api.friends_ids("USERNAME") | |
no_followers = set(following) - set(followers) | |
total_unfollowed = 0 | |
print("Unfollowing %s people who don't follow you back" % len(no_followers)) | |
print("This will take approximately %s minutes." % (len(no_followers) / 60.0)) | |
answer = input("Are you sure? [Y/n]").lower() | |
if answer and answer[0] != "y": | |
sys.exit(1) | |
for nf in no_followers: | |
print("Unfollowing %s" % nf) | |
try: | |
api.destroy_friendship(nf) | |
total_unfollowed += 1 | |
except (tweepy.RateLimitError, tweepy.TweepError) as e: | |
print(e) | |
print(" .. completed, sleeping for 1 second.") | |
time.sleep(1) | |
print(str(total_unfollowed) + 'Unfollowed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment