Skip to content

Instantly share code, notes, and snippets.

@cosmos-sajal
Last active October 27, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosmos-sajal/92779d2e5658e39e5eda366abc415663 to your computer and use it in GitHub Desktop.
Save cosmos-sajal/92779d2e5658e39e5eda366abc415663 to your computer and use it in GitHub Desktop.
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy import api
from tweepy.streaming import StreamListener
import json
#consumer key, consumer secret, access token, access secret.
ckey="<ckey>"
csecret="<csecret>"
atoken="<atoken>"
asecret="<asecret>"
class listener(StreamListener):
def on_data(self, data):
all_data = json.loads(data)
tweet = all_data["text"]
print(tweet)
def on_error(self, status):
print(status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["HillaryClinton"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment