import twitter_login import twitter import sys q = 'basketball' # Comma-separated list of terms print >> sys.stderr, 'Filtering the public timeline for track="%s"' % (q,) twitter_api = twitter_login.get_api() twitter_stream = twitter.TwitterStream(auth=twitter_api.auth) stream = twitter_stream.statuses.filter(track=q) for tweet in stream: print tweet['text'].encode('utf8')
# top_n_scored = sorted(top_n_scored, key=lambda s: s[0]) # # # Decorate the post object with summaries # return dict(top_n_summary=[sentences[idx] for (idx, score) in top_n_scored], # mean_scored_summary=[sentences[idx] for (idx, score) in mean_scored]) def analyze_favorites(twitter_api, screen_name, entity_threshold=2): favs = twitter_api.favorites.list(screen_name=screen_name, count=200) print "Number of favorites:", len(favs) # Figure out what some of the common entities are, if any, in the content common_entities = get_common_tweet_entities(favs, entity_threshold=entity_threshold) pt = PrettyTable(field_names=['Entity', 'Count']) [ pt.add_row(kv) for kv in common_entities ] pt.align['Entity'], pt.align['Count'] = 'l', 'r' # Set column alignment print print "Common entities in favorites..." print pt print print "Some statistics about the content of the favorities..." print analyze_tweet_content(favs) # Sample usage twitter_api = get_api() print "OK" analyze_favorites(twitter_api, "ptwobrussell")