Created
December 17, 2013 16:46
-
-
Save cbeach/8008108 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
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