Created
November 12, 2012 04:41
-
-
Save hiway/4057558 to your computer and use it in GitHub Desktop.
Utility to trim down your twitter following by moving users to lists and unfollowing automatically.
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 | |
# -*- coding: utf-8 -*- | |
import sys | |
try: | |
import tweepy | |
except: | |
raise Exception('Install tweepy library first! (pip install tweepy)') | |
try: | |
from twitter_auth_settings import * | |
except: | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
ACCESS_KEY = '' | |
ACCESS_SECRET = '' | |
if not ACCESS_KEY: | |
raise Exception('Set up credentials from dev.twitter.com ' | |
'in the script.') | |
if len(sys.argv) > 2: | |
slug = sys.argv[1] | |
usernames = sys.argv[2:] | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) | |
api = tweepy.API(auth) | |
me = api.me() | |
for username in usernames: | |
try: | |
user = api.get_user('%s' % username) | |
except: | |
print 'User %s not found!' % username | |
continue | |
if api.add_list_member(slug=slug, id=user.id): | |
# if user was successfully added to list, | |
# check if we're following the user: | |
if api.exists_friendship(me.id, user.id): | |
# Unfollow | |
api.destroy_friendship(user.id) | |
print "Now following %s via %s" % (user.screen_name, slug) | |
else: | |
print ("Usage: follow_via_list.py [list-slug] " | |
"[username1, username2, ...]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage notes: