1

My code gives continuous data, but I wanted to filter the data to last five minutes. Additionally, I wanted to report it every 1 minute. What I need to do for that?

try:
    import json
except ImportError:
    import simplejson as json

from twitter import Twitter, OAuth, TwitterHTTPError, TwitterStream

ACCESS_TOKEN = 'secret'
ACCESS_SECRET = 'secret'
CONSUMER_KEY = 'secret'
CONSUMER_SECRET = 'secret'

oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)

twitter_stream = TwitterStream(auth=oauth)

iterator = twitter_stream.statuses.filter(track="car", language="en")

for tweet in iterator:
    try:
        if 'text' in tweet: 
            print tweet['user']['name'] 
            print tweet['user']['statuses_count']
            # print '\n'
            for hashtag in tweet['entities']['hashtags']:
                hashtags.append(hashtag['text'])
            print hashtags

    except:
        continue

Thanks in advance.

Saket Mittal
  • 3,726
  • 3
  • 29
  • 49
  • For the love of all that is good a decent in this world, please don't catch exception and not handle them at all. – James Mertz Aug 27 '15 at 19:13
  • 1
    There's two separate questions here. "How do I make a program run/display something every minute?" which is likely a duplicate, and "How do I use the Python Twitter API to filter data not from the last five minutes?" – Two-Bit Alchemist Aug 27 '15 at 20:09
  • @Two-BitAlchemist yes i need to implement both in above code so help me if you have any info – Saket Mittal Aug 27 '15 at 20:16

0 Answers0