Twitter Stream API with database

python and steam api tweeter
Twitter is holy grail for data and behavior science.  Data from twitter can be biased but its still good way to see how mass react or how certain chain unfolds. As all almost all data you share in twitter is publicly available(with API limit), we can do a lot of analysis on these. Twitter has limitation on data range of data you can extract but has feature to stream the live tweet which we can store for
future use.

In this tutorial, we will connect to twitter API and get the live twitter feed, store the feed into SQLite database. We will be using SQLachemy, so you can modify this for database of your choice.

Let get started,
Sign up to twitter develop platform and make new app. Once you make app get the four keys from app detail i.e "customer_key", "customer_secret", "access_token", "access_secret". and store it in config file as dict.
Here code code to get live feed and store it into sqlite database:

Here is first 5 rows of twitter stored in twitter_db.
You can use this data to make dashboard or analysis.


Quote from Book I am reading:
People love to say, “Give a man a fish, and he’ll eat for a day. Teach a man to fish, and he’ll eat for a lifetime.” What they don’t say is, “And it would be nice if you gave him a fishing rod.” That’s the part of the analogy that’s missing.  
― Trevor Noah, Born a Crime: Stories From a South African Childhood 

Unknown

I'm a Data-holic. I'm passionate about learning new things and playing with data. This blog is a place where I want to share my data analysis tips and tricks, data visualization and automation tips and tricks.

No comments:

Post a Comment