This Python script performs a Twitter sentiment analysis by retrieving recent tweets containing a specific keyword or topic and analyzing the sentiment of the tweet's text. Sentiment analysis is a powerful tool that helps determine the emotional tone behind a piece of text—whether it's positive, negative, or neutral.
It queries the Twitter API using the search_recent_tweets endpoint to retrieve tweets containing the defined keyword (e.g., "stocks"). The lang
filter ensures that only English tweets are retrieved.For each tweet, the script uses TextBlob to analyze the sentiment: Polarity determines whether the sentiment is positive, neutral, or negative. Subjectivity indicates the level of opinion or bias in the tweet.
The script displays the following information for each tweet: Author ID Tweet text Timestamp Sentiment scores (Polarity and Subjectivity)