Twitter sentiment analysis with python library

With the help of twitter app credentials, i have started working on another set of sentiment analysis.

I have used couple of popular libraries this time.

  • TextBlob
  • Tweepy

TextBlob is used to check the polarity of the given text.

And tweepy is used to get the tweets from real-time data.

To use tweepy, first we need to create an app in twitter environment. This can be done in their developers site. Once app is created we need to get the following tokens from it.

api_key = 'XXXX'

api_key_secret = 'XXXX'

access_token = 'XXXX'

access_token_secret = 'XXXX'

You can find the entire main.py file content below.

from textblob import TextBlob
import tweepy

api_key = 'XXXX'
api_key_secret = 'XXXX'
access_token = 'XXXX'
access_token_secret = 'XXXX'

auth_handler = tweepy.OAuthHandler(consumer_key=api_key, consumer_secret=api_key_secret)
auth_handler.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth_handler)

search_terms = 'peace'
tweet_count = 200

tweets = tweepy.Cursor(api.search_tweets, q=search_terms, lang='en').items(tweet_count)

overall_polarity = 0
positive_polarity = 0
neutral_polarity = 0
negative_polarity = 0

for tweet in tweets:
cleaned_up_text = tweet.text.replace('RT', '')
if cleaned_up_text.startswith(' @'):
position = cleaned_up_text.index(':')
cleaned_up_text = cleaned_up_text[position + 2:]
if cleaned_up_text.startswith('@'):
position = cleaned_up_text.index(' ')
cleaned_up_text = cleaned_up_text[position + 2:]

analysis = TextBlob(cleaned_up_text)
overall_polarity += analysis.polarity

if analysis.polarity > 0.00:
positive_polarity += 1
elif analysis.polarity < 0.00:
negative_polarity += 1
print(cleaned_up_text)
elif analysis.polarity == 0.00:
neutral_polarity += 1

print(f'overall: {overall_polarity}')
print(f'positive: {positive_polarity}')
print(f'negative: {negative_polarity}')
print(f'neutral: {neutral_polarity}')

The Art of Planning

“Don’t think about the start of the race, think about the ending” – Usain Bolt

One common question, I’m receiving from most of my friends is

How you are managing your time to do these many things?

Actually, they meant how I’m being active in learning new tools, reading books, making progress in blogging, posting random pieces of stuff at social media and all.

I took this question seriously and planned to answer them all via this blog post.

Planning is the ultimate key to unlock these activities.

 

Why planning?

A couple of years back I too had the same set of questions on how to create an action plan and how to efficiently work on it.

I have started reading some books, watching some YouTube videos, and listening to other people stories on how they are managing time on personal life as well towards their passion.

I have written all good ideas I have collected from the various medium in a notepad.

Later, I have clearly picked up the items which suit me.

On most time management & goal settings stories, I have found one common habit or ground rule.

It’s PLANNING!

 

How I have prepared my action plan?

Then, I have come up with an idea to create an action plan. I have started listing all things I wished or dreamed to complete in next few weeks or months or years.

Once I have listed all the items I wish to do. It looks like a large list, kind of watching a horror movie at midnight.

Instead of making progress in all the items at the same time, I have come up with idea of

  • prioritizing
  • categorizing

I have started to prioritize the list based on Career growth and Personal growth from most to least important. (Kind of bubble sort, decided which bubbles I need to burst first)

After prioritizing, Its time for categorizing.

In my case, I have decided to Categorize my action plan based on what time frame I have to achieve it.

So, the categories will look like this

  • Long-term
  • Short term
  • Daily
  • Today

The long-term goal is something I planned to achieve in few years. Short term goal is the items I wish to cover in minimum one year. Daily goals are like checklist I should follow on daily basis. Today board is to plan for the day ahead.

Ultimately, my planning board looks like following

planning

I shall create a separate post on how I plan for the day ahead.

I used to keep this list on my desktop screen always using sticky notes options on my windows laptop.

Basically, I’m a sticky note lover. And below is my monitor screen filled with sticky notes 🙂

sticky_notes_overused

 

Next big step

We have planned everything, whats the next big step?

Executing

Yes! A very organized plan will help you to make consistent progress to reach your goal.

 

Hope you have like this post, please follow this blog to receive more updates.

And also Please comment your thoughts or share your ideas on planning in the comment section.

 

Happy planning!