Created
December 6, 2012 17:44
-
-
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
This file contains 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
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