We can use our model in order to classify tweets in real time using Twitter’s API. In order to simplify things, we will make use of a very popular wrapper library for the API, tweepy (https://github.com/tweepy/tweepy). Installation is easily achieved with pip install tweepy. The first step to accessing Twitter programmatically is to generate relevant credentials. This is achieved by navigating to https://apps.twitter.com/ and selecting Create an app. The application process is straightforward and should be accepted quickly.
Using tweepy's StreamListener, we will define a class that listens for incoming tweets, and as soon as they arrive, it classifies them and prints the original text and predicted polarity. ...