Last active
August 29, 2015 14:07
-
-
Save craigpalermo/bbfa82116e0f24b3f7b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tweepy import OAuthHandler | |
from tweepy.streaming import StreamListener | |
from tweepy import Stream | |
from tweepy import API | |
from cleverbot import Cleverbot | |
import json | |
import sys | |
consumer_key = "" | |
consumer_secret = "" | |
access_token = "" | |
access_token_secret = "" | |
class StdOutListener(StreamListener): | |
""" A listener handles tweets are the received from the stream. | |
This is a basic listener that just prints received tweets to stdout. | |
""" | |
def on_data(self, data): | |
print json.loads(data)['text'] | |
return True | |
def on_error(self, status): | |
print status | |
if __name__ == '__main__': | |
l = StdOutListener() | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
# send a tweet | |
# api = API(auth) | |
# api = api.update_status("This is a test tweet. Please disregard.") | |
if sys.argv[0]: | |
term = sys.argv[1] | |
stream = Stream(auth, l) | |
stream.filter(track=[term]) | |
else: | |
print "No search term given." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment