Created
November 24, 2012 00:09
-
-
Save ciembor/4137786 to your computer and use it in GitHub Desktop.
Shows retweets to tweets ratio.
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
# -*- coding: utf-8 -*- | |
# https://github.com/ryanmcgrath/twython | |
from twython import Twython | |
# get your keys: https://dev.twitter.com/apps/new | |
t = Twython(app_key='jwh(...)PnQ', | |
app_secret='G2H(...)kSs', | |
oauth_token='284(...)Ytv', | |
oauth_token_secret='n8w(...)3Kk') | |
# https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline | |
# "count - Specifies the number of tweets to try and retrieve, | |
# up to a maximum of 200 per distinct request." | |
# | |
# https://github.com/ryanmcgrath/twython/wiki/Timeline-Access | |
tweets = t.getUserTimeline(count=200) | |
retweets_count = 0 | |
for tweet in tweets: | |
retweets_count += tweet['retweet_count'] | |
ratio = float(retweets_count) / len(tweets) | |
print('Retweets to tweets ratio is "%.4f".' % ratio); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment