Skip to content

gregory-mc/twitter-streaming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Streaming

NOTE: You need to get API KEYS first

Description:

This algorithm allows you to get tweets according to a word or tag, then tweets are saved in a database (SQLite) for your purposes

  1. Define Twitter Listener: Here you choose how and which tweets are saved into database. I used just few parameters. You can check this in Tweepy Docs
class TweetsListener(tweepy.StreamListener):
  1. Define API KEYS: You need to have these API KEYS, if you don't have them. Please, check this web: Twitter
  2. DB Connection: I used SQLite but you can use any DB, just make sure you are using appropiate library to get connected to your database. You can use SQLAlchemy but you will have to add and change some lines of code.
con = sqlite3.connect("tweets.db") #database name
cursorObj = con.cursor()
cursorObj.execute("CREATE TABLE IF NOT EXISTS tweets(created date,user text, tweet text, user_name text,location text, retweets integer, likes integer)")
con.commit()
  1. Streaming:
stream = TweetsListener()
streamingApi = tweepy.Stream(auth=api.auth, listener=stream)
streamingApi.filter(track=['#DebatePresidencialJNE']) # Peruvian Subject

You can change the word in track to find tweets about your subject 5. Final: I used pandas to read the data saved in the db but you can continue doing whatever you need. Pre processing, Spark, move to another database, etc.

About

Algoritmo para obtener tweets mediante streaming en una base de datos sqlite utilizando python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published