Python visualization of the frequency of tweets in a given topic in Twitter

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.