I have a working script that successfully gathers tweets that mention \"stackoverflow\". However, I want to run the script in iPython (rather than executive a separate .py f
add the following code to your existing code. 'fetched_tweets.txt' is the name of file in which you want to save the tweets which is opened in 'a'(append mode).
class StdOutListener(StreamListener):
def on_data(self, data):
#print data
with open('fetched_tweets.txt','a') as tf:
tf.write(data)
return True
def on_error(self, status):
print status
You can do it by redirecting output to a file:
in Terminal/CMD just type python twitter_streaming.py > twitter_data.txt
for appending to an existing file use >>
instead of >
.