Collect Tweets on #Corona from Twitter using Tweepy

With the #Corona and #StayHome trending throughout the world, I got curious about what’s going on in people’s minds? How Moms are reacting with the school closed until the next session or how the high school kids are responding? Different people handling it in their own way in an attempt to stay safe. In this crisis period, Let’s find out what’s there on everyone’s mind!

Twitter can assist in analyzing human feelings. So, in this post, we will see how to connect to Twitter and collect the tweets on some particular topic using Tweepy.

1. Create Twitter Developer Account

We need to do the below  steps:

  1. Set up a Twitter account if you do not have one already
  2. Using the Twitter account, we need to apply for a Developer Account first. The Link is here.
  3. Fill in some basic details like the reason to create a developer account or how you plan to use the Twitter API etc.
  4. After filling in the details, accept the Developer Agreement and verify the email address.
  5. Once all the details are filled in, a notification will pop up something like below:

Once your new Twitter Developer account application is reviewed by Twitter then they will send you an approval email.

 

2. Set up Twitter App

  1. Login to Twitter Developer Account
  2. Click on “Your name” on the right side top
  3. Then, click on “Apps”
  4. Next, click on “Create an App”  
  5. Fill in App name and other details and click “Create
  6. Once the APP is created the keys and he tokens o access Twitter will be generated

3. Install Libraries

Install the Tweepy and Twitter packages.

Now, we are ready to begin querying Twitter to see what we can learn from tweets! So, let’s be clear about what are we trying to do in this post. If we open Twitter and search for some topic, we see all the tweets below.

We want to achieve the same results by writing a few lines of python code. Then, in the next post, we can work on Sentiment Analysis and dig further. 

I log in to Twitter and did an advanced search with words like “#corona” and language “English” and days from “01-Jan-2020”. in the search bar, it is searching for #corona lang:en since:2020-01-01″

Let’s take a look at my first tweet result:

Let’s start coding and see if we can get the same result.

Yes, I got it! If I take a look at my output, the first tweet is from Scott Ford wishing “Happy Birthday”!

So, now we know how to search for tweets the way we do on Twitter. Let’s collect these tweets from Twitter and do some Text Analysis and then finally work on Sentiment Analysis. 

For Reference:

My other posts on Twitter Streaming and Analysis are below:

  1. Text Analytics on #coronavirus trends in Twitter using Python
  2. Streaming Tweets from Twitter using Tweepy and Text Analytics

Thank You For Reading!

0

Leave a Reply

Your email address will not be published. Required fields are marked *