Skip to content

Instantly share code, notes, and snippets.

@cbeach
Created December 17, 2013 16:46
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 cbeach/8008108 to your computer and use it in GitHub Desktop.
Save cbeach/8008108 to your computer and use it in GitHub Desktop.
import time
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from config import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
class Listener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def __init__(self):
self.record = open('data/twitter_stream.json', 'a')
def on_data(self, data):
print data
self.record.write(data + '\n\r')
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = Listener()
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
while True:
stream = Stream(auth, l)
stream.filter(track=['bitcoin', 'litecoin', 'lite coin', 'bit coin', 'btc', 'ltc',
'namecoin', 'name coin', 'nmc'])
time.sleep(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment