コード例 #1
0
    def handle(self, *args, **options):
        auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY,
                                   settings.TWITTER_CONSUMER_SECRET)
        auth.set_access_token(settings.TWITTER_ACCESS_TOKEN,
                              settings.TWITTER_ACCESS_TOKEN_SECRET)
        api = tweepy.API(auth)

        if options['query']:
            for tweet in tweepy.Cursor(api.search,
                                       q=options['query'],
                                       rpp=100,
                                       result_type="recent",
                                       include_entities=True,
                                       lang="en").items(options['limit']):
                tweet = json.loads(json.dumps(tweet._json))
                if 'retweeted_status' in tweet:
                    print('%s skipping - tweet is a retweet' % (tweet['id']))
                    continue
                if 'possibly_sensitive' in tweet:
                    if tweet['possibly_sensitive']:
                        print('%s skipping - tweet is possibly sensitive' %
                              (tweet['id']))
                        continue
                save_tweet.delay(tweet)
                print('%s processed - send tweet to queue' % (tweet['id']))

        if options['id']:
            for tweet in api.statuses_lookup(options['id'],
                                             include_entities=True):
                tweet = json.loads(json.dumps(tweet._json))
                save_tweet.delay(tweet)
コード例 #2
0
    def on_data(self, tweet):

        tweet = json.loads(tweet)
        # if more than 1% of firehorse is addressed by filter, a limit message is sent with number of missed tweets
        if 'limit' in tweet:
            logger.warning("Missed tweets: " + str(tweet['limit']['track']))
            return
        if 'retweeted_status' in tweet:
            logger.debug('skipping - tweet is a retweet')
            return
        save_tweet.delay(tweet)
        logger.debug('new tweet')
コード例 #3
0
    def on_data(self, tweet):

        tweet = json.loads(tweet)
        # if more than 1% of firehorse is addressed by filter, a limit message is sent with number of missed tweets
        if 'limit' in tweet:
            logger.warning("Missed tweets: " + str(tweet['limit']['track']))
            return
        if 'retweeted_status' in tweet:
            logger.debug('skipping - tweet is a retweet')
            return
        if 'possibly_sensitive' in tweet:
            if tweet['possibly_sensitive']:
                logger.debug('skipping - tweet is possibly sensitive')
                return
        save_tweet.delay(tweet)
        logger.debug('new tweet')
コード例 #4
0
ファイル: twitter_import.py プロジェクト: hdaube/emc_phoenix2
    def handle(self, *args, **options):
        auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
        auth.set_access_token(settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET)
        api = tweepy.API(auth)

        if options['query']:
            for tweet in tweepy.Cursor(api.search,q=options['query'], rpp=100, result_type="recent", include_entities=True, lang="en").items(options['limit']):
               tweet = json.loads(json.dumps(tweet._json))
               if 'retweeted_status' in tweet:
                   print('%s skipping - tweet is a retweet' %(tweet['id']))
                   continue
               if 'possibly_sensitive' in tweet:
                   if tweet['possibly_sensitive']:
                       print('%s skipping - tweet is possibly sensitive' %(tweet['id']))
                       continue
               save_tweet.delay(tweet)
               print('%s processed - send tweet to queue' %(tweet['id']))

        if options['id']:
            for tweet in api.statuses_lookup(options['id'], include_entities=True):
               tweet = json.loads(json.dumps(tweet._json))
               save_tweet.delay(tweet)