import os

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#Variables that contains the user credentials to access Twitter API
ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET']
CONSUMER_KEY = os.environ['CONSUMER_KEY']
CONSUMER_SECRET = os.environ['CONSUMER_SECRET']


class StdOutListener(StreamListener):
    """
    Basic listener that output tweet to stdout
    """

    def on_data(self, data):
        print(data)
        return True

    def on_error(self, status):
        print('ERROR', status)


if __name__ == '__main__':
    l = StdOutListener()
    auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    stream = Stream(auth, l)

    try:
        stream.filter(track=[
            # 'fifa',
            # 'worldcup',
            'ENGCRO',
        ])
    except KeyboardInterrupt:
        pass

