1

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)
bkm
  • 109
  • 1
  • 8
  • Have you found the solution for this? – Neeraj Pandey Jul 22 '16 at 20:48
  • I made it to work by since and until operator in Twitter Search API. However, there were instances when I got tweets outside the date range or within the date range. The best approach would be to extract tweets from the Twitter Search API by the desired date range multiple time and then keeping the relevants based on their post date. – bkm Jul 23 '16 at 21:36

0 Answers0