Skip to content

Instantly share code, notes, and snippets.

@jd7h
Last active August 22, 2019 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jd7h/02094c6e1a79b1ee069635a452d7b0e7 to your computer and use it in GitHub Desktop.
Save jd7h/02094c6e1a79b1ee069635a452d7b0e7 to your computer and use it in GitHub Desktop.
Twitter following detox python script
#!/usr/bin/python
'''
USE AT YOUR OWN PERIL <3
Before using the script,
fill in your API keys,
fill in the whitelist,
do a small test run with a small list.
'''
import time
# sudo pip3 install python-twitter
# for docs, see https://python-twitter.readthedocs.io/en/latest/twitter.html
import twitter
# connect to api with apikeys
# if you don't have apikeys, go to apps.twitter.com
api = twitter.Api(consumer_key='twitter consumer key',
consumer_secret='twitter consumer secret',
access_token_key='the_key_given',
access_token_secret='the_key_secret')
# get followers
friends = api.GetFriends()
friend_ids = [friend.id for friend in friends]
# create private list
backuplist = api.CreateList(name="following-backup",mode="private",description=("Users I followed on " + time.strftime("%Y-%m-%d")))
# backup users from 'Following' to list
for friend_id in friend_ids:
result = api.CreateListsMember(list_id=backuplist.id,user_id=friend_id)
time.sleep(1)
# make whitelist (optional)
whitelist = [] #fill this list with ids of people you want to keep following
# mass-unfollow
for friend_id in friend_ids:
if friend_id not in whitelist:
result = api.DestroyFriendship(friend_id)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment