Lesser Evil (lesser-evil-cli
) is a hosted Ruby gem for the command line which applies a third-party, open-source sentiment analysis tool to collect negative-affect tweets regarding the 2016 U.S. Presidential candidates. The user chooses the candidate ("Trump" or "Clinton") and the negativity threshold ("angry" or "very angry").
The fetch_tweets
method in the Tweet Controller is the primary engine of the application. It performs the following tasks:
- Retrieves a batch of tweets. It calls (line 29) the
get_batch
method which makes GET requests to the Twitter Search API. The request includes search terms, desired number of results, and the maximum ID (i.e., the most recent ID from which to start the search) - Filters them according to sentiment. The
if
statement of line 36 tests for sentiment negativity and user-specified intensity - Creates a TweetSlim object from each matched tweet (line 37)
- Prints each TweetSlim object to the screen
- Saves each TweetSlim object to an array
- Repeats the above steps until the desired number of matched tweets is reached (
while
loop of line 28) - Returns the array (line 44)
fetch_tweets
is, as mentioned, the primary engine of the application, the method that does most of the work. In its current incarnation, the gem is a command-line application. But with some adjustments it can do double-duty, functioning additionally as part of a full-stack application. The second snippet comprises a couple of React components that are the beginning of that app.