Skip to content

Instantly share code, notes, and snippets.

@shackenberg
Created December 6, 2012 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shackenberg/4226438 to your computer and use it in GitHub Desktop.
Save shackenberg/4226438 to your computer and use it in GitHub Desktop.
Script to find the twitterer who are responsible for the most tweets in your timeline
from collections import Counter
from twython import Twython
import operator
app_key = 'XXX'
app_secret = 'XXX'
## init OAuth
t = Twython(app_key=app_key,
app_secret=app_secret)
auth_props = t.get_authentication_tokens()
oauth_token = auth_props['oauth_token']
oauth_token_secret = auth_props['oauth_token_secret']
print 'Go to Twitter via: %s' % auth_props['auth_url']
raw_input("Press Enter when you authorized the app")
t = Twython(app_key=app_key,
app_secret=app_secret,
oauth_token=oauth_token,
oauth_token_secret=oauth_token_secret)
authorized_tokens = t.get_authorized_tokens()
t = Twython(app_key=app_key,
app_secret=app_secret,
oauth_token=authorized_tokens['oauth_token'],
oauth_token_secret=authorized_tokens['oauth_token_secret'])
## getting the timeline
timeline = t.getHomeTimeline(count=200, exclude_replies=True)
max_id = 0
new_max_id = 1
while max_id != new_max_id:
max_id = timeline[-1][u'id']
more_tweets = t.getHomeTimeline(count=200, max_id=max_id, exclude_replies=True)
timeline = timeline + more_tweets
new_max_id = timeline[-1][u'id']
## printing the main offenders
spammers = Counter([i[u'user'][u'screen_name'] for i in timeline])
sorted_spammers = sorted(spammers.iteritems(), key=operator.itemgetter(1), reverse=True)
for i in sorted_spammers:
print str(i[1]) + '\t' + 'www.twitter.com/' + i[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment