KaterynaD / TweetsListener

Collects tweets and performs sentiment analysis based on emoticons and NLP (TextBlob)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TweetsListener

TweetsListener.py provides classes to perform tweets collection and sentiment analysis

There are several classes based on StreamListener from tweepy

  1. TweetsListener is a base class to listen tweets only and stop listening when a specific number of tweets collected or time listening is out. If both parameters are 0 then it can run forever.
  2. TWeetSentimentAnalyzed analyzes the tweet emotions based on emoticons in the tweet if any or applies NLP procedures from TextBlob package to perform sentiment analysis
  3. TWeetsToFile saves collected tweets in a csv file. In addition to the limit number of tweets or maximum time collection reached, the collection of tweets can be stopped when the file reaches a limit. The class can split the data in several files, based on the tweets number or an individual file size.
  4. In addition to the tweet itself, TWeetsCoordinatesToFile saves GEO info in a separate file. "_geo_" is added to the file name The GEO file is in csv format, many-to-one relations to the tweets file All files total size is taken into account to stop tweets collection at file_size_limit Only tweets file is splitted in multiply files
  5. TWeets class inherits TWeetsCoordinatesToFile and TWeetSentimentAnalyzed methods. It saves the tweet, it's sentiments in a csv file and the coordinates in a separate file
  6. TWeetsTotals saves only total sentiments daily in a csv file. There is also hourly data but they are overwritten

The script has a usage example of the classes

To run the script you need to have a Twitter Developer Account.

The usage example expects the account details and other parameters in a project resources yaml-formatted file.

To collect tweets, use the following command, where search_term is your search term and ProjectResources.yml is optional, project resources file in yaml format. If it is not provided, ProjectResources.yml is used by default

python TweetsListener.py search_term ProjectResources.yml

To use a multi-word term, enclose it in quotation marks

About

Collects tweets and performs sentiment analysis based on emoticons and NLP (TextBlob)


Languages

Language:Python 100.0%