I would like to write a program that can pull tweets from Twitter based on keywords, usernames and a date range. I have used Tweepy to write a program to extract tweets from the Streaming API. Currently, it brings tweets based on keywords OR usernames.
I would like to change the program to include a filtering critera: keywords AND usernames AND date_range. How should I modify the program ?
Python Version Used: 2.7
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Removed my authentication parameters because of confidentiality
consumer_key=
consumer_secret=
access_token=
access_token_secret=
class StdOutListener(StreamListener):
def on_data(self, data):
saveFile= open('save_tweets.txt','a')
saveFile.write(data)
saveFile.write('\n')
return True
def on_error(self, status):
print(status)
def on_limit(self, track):
return
def on_timeout(self):
print ('time out')
return
def on_disconnect(self, notice):
print (notice)
return
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
track_list=['art','gallery']
follow_list=['70100659','12804422']
stream.filter(track=track_list, follow=follow_list)