Get startedGet started for free

Streaming tweets

Now that you have set up your authentication credentials, it is time to stream some tweets! In pre-code, we have already defined the Tweet Stream Listener Class, just as Hugo did in the introductory video. You can find the code for the Tweet Stream Listener Class here.

Your task is to create the Stream object and to filter tweets according to particular keywords.

This exercise is part of the course

Importing Data in Python

View Course

Exercise instructions

  • Create your Stream object with authentication by passing to tweepy.Stream() the authentication handler auth and the Stream listener l;
  • To filter Twitter Streams, pass to stream.filter() a list containing the desired keywords 'clinton', 'trump', 'sanders', and 'cruz'.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Initialize Stream listener
l = MyStreamListener()

# Create you Stream object with authentication
stream = tweepy.Stream(____, ____)


# Filter Twitter Streams to capture data by the keywords:
stream.filter(____)
Edit and Run Code