Skip to content

Instantly share code, notes, and snippets.

View ant358's full-sized avatar
🎯
Focusing

Anthony Wynne ant358

🎯
Focusing
  • Plymouth, UK
View GitHub Profile
@ant358
ant358 / tweet_listener.py
Created January 5, 2019 17:33 — forked from hugobowne/tweet_listener.py
Here I define a Tweet listener that creates a file called 'tweets.txt', collects streaming tweets as .jsons and writes them to the file 'tweets.txt'; once 100 tweets have been streamed, the listener closes the file and stops listening.
class MyStreamListener(tweepy.StreamListener):
def __init__(self, api=None):
super(MyStreamListener, self).__init__()
self.num_tweets = 0
self.file = open("tweets.txt", "w")
def on_status(self, status):
tweet = status._json
self.file.write( json.dumps(tweet) + '\n' )
self.num_tweets += 1