CODE:
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2014-7-21
@author: guaguastd
@name: find_popular_tweets.py
'''
if __name__ == '__main__':
# import login, see http://blog.csdn.net/guaguastd/article/details/31706155
from login import twitter_login
# get the twitter access api
twitter_api = twitter_login()
# import search
from search import search_for_tweet
# import tweet
from tweet import find_popular_tweets
# pip install prettytable
from prettytable import PrettyTable
while 1:
query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
if query == 'exit':
print 'Successfully exit!'
break
statuses = search_for_tweet(twitter_api, query)
tweets = find_popular_tweets(twitter_api, statuses)
# Slice off the first 10 from the sorted results and display each item in the tuple
pt = PrettyTable(field_names=['Retweet_count', 'Text'])
[pt.add_row(row) for row in sorted(tweets, reverse=True)[:10]]
pt.max_width['Text'] = 50
pt.align = 'l'
print pt
RESULT:
Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Google Length of statuses 100 Length of statuses 199 +---------------+----------------------------------------------------+ | Retweet_count | Text | +---------------+----------------------------------------------------+ | 25352 | RT @Michael5SOS: 5 MINUTES TILL GOOGLE STREAM