This project utilizes the Twitter API to search tweets based on user-provided criteria with the option to run various Natural Language Processing (NLP) scripts against. The search query is limited to tweets from the past seven days, based on developer account permitted use. The following NLP capabilities currently exist in this repository:
- Sentiment Analysis: calculates the average sentiment of tweets and breaks down into positive, negative, neutral, and compound scores metrics. Provides plot and table to summarize the output of a given keyword.
- Word Cloud: creates a word cloud of frequently used words in a collection of tweets for a given keyword.
- create a '.env' file in the main directory
- create a BEARER_TOKEN variable with your associated bearer token from twitter dev account
- Template: BEARER_TOKEN=''
- Note - .env requires line 2 to be a whitespace line
- In a bash terminal run 'source ./setup.sh' to install all dependencies
- edit the parameters in config.ini to specify the tweet parameters for one or two queries
- The 'keyword' for QUERY 1 is required - this value can be a word, a hashtag or a longer phrase
- Values should not include quotes (single or double)
- The 'keyword' for QUERY 2 is optional - if not specified, the script will only run the first keyword query
- the 'language' for PARAMETERS only supports english at this time (lang:en) and will be used for all queries
- the 'num_tweets' for PARAMETERS is the number of tweets you would like to retrieve for each query, this is used for all queries
- Be sure to save config.ini (see below for example configuration)
- The 'keyword' for QUERY 1 is required - this value can be a word, a hashtag or a longer phrase
- in a bash terminal, the following scripts can be run to execute different NLP tasks: python analyze_sentiment.py python create_word_cloud.py
The following commands can be run for local unit testing and code coverage: python -m pytest python -m pytest --cov=helpers
[QUERY 1]
keyword = #LIVTour
[QUERY 2]
keyword = #PGATour
[PARAMETERS]
language = lang:en
num_tweets = 1000