CODE:
#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-7-8@author:guaguastd@name:plot_frequencies_words.py" if _ _name__ = = ' __main__ ': #import JSON # import Counter from collections Import Counter # import Search From search Import Search_for_tweet # import visualize from visualize import visualize_for_frequencies # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from login import Twitter_login # ge T the twitter access API Twitter_api = Twitter_login () # import tweet from tweet import Extract_tweet_entitie s while 1:query = Raw_input (' \ninput of the query (eg. #MentionSomeoneImportantForYou, exit to quit): ') if query = = ' exit ': print ' successfully exit! ' Break statuses = Search_for_tweet (twitter_api, query) status_texts,screen_names,hashtags,words = Ext Ract_tweet_entities (statuses) word_counts = sorted (COunter (words). VALUES (), reverse=true) visualize_for_frequencies (word_counts, "Word Rank", "Freq")
RESULT:
Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYouLength of statuses 100L Ength of statuses 196
Python visualization of the frequency of tweets in a given topic in Twitter