Created
January 1, 2014 12:29
-
-
Save zekzekus/8207700 to your computer and use it in GitHub Desktop.
a dirty script to help myself unfollowing a lot of users from twitter
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
import twitter # pip install python-twitter | |
import pickle | |
def main(): | |
# create an app an set read/write permissions. credidentials below | |
api = twitter.Api( | |
consumer_key='', | |
consumer_secret='', | |
access_token_key='', | |
access_token_secret='') | |
# take all id numbers of users you are following | |
friend_ids = api.GetFriendIDs() | |
print "You are following %d users" % len(friend_ids) | |
# a whitelist to hold users you do NOT want to unfollow. with this file | |
# you can quit anytime and resume later and whiltelisted users wont listed | |
# again | |
try: | |
whitelist = pickle.load(open("whitelist.obj", "rb")) | |
except Exception: | |
whitelist = [] | |
try: | |
for f in reversed(friend_ids): | |
if f in whitelist: | |
continue | |
try: | |
friend = api.GetUser(f) | |
except twitter.TwitterError: | |
continue | |
print "===========================================================" | |
print "%s - %s - %s - %s" % (friend.screen_name, friend.name, | |
friend.description, | |
print_status(friend.status)) | |
what = raw_input("ENTER to delete, S to skip, or Q to quit.") | |
if what in ['q', 'Q']: | |
break | |
elif what in ['s', 'S']: | |
whitelist.append(f) | |
elif what == '': | |
print "Destroyed the fucking!" | |
destroyed = api.DestroyFriendship(f) | |
print "%s unfollowed" % (destroyed.screen_name) | |
else: | |
print "Unknown command. No action taken." | |
except Exception, e: | |
print e | |
raise | |
finally: | |
pickle.dump(whitelist, open("whitelist.obj", "wb")) | |
def print_status(status): | |
if status: | |
return "%s - %s" % (status.created_at, status.text) | |
return "None" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment