def is_reputation_affecting(tweet): senti_score = TweetSentimentEvaluator.rate_sentiment(tweet) negative = senti_score[len(senti_score) - 1] positive = senti_score[0] if int(negative) >= 2 or int(positive) >= 2: return True else: return False
def run(self): while True: status = self.tweet_queue.get() try: if not self.spam_detector.is_spam(status) and utility.is_reputation_affecting(status): id_str = status['id_str'] status['reputation_dimension'] = self.dimension_classifier.classify(status) status['related_entity'] = utility.fetch_entity(status) status['sentiment_score'] = TweetSentimentEvaluator.rate_sentiment(status) self.tweets_buffer.append(Tweet(tweet_id=id_str, tweet=status, created_at=timezone.now())) print 'Tweet %s added to buffer, buffer size %d' % (id_str, len(self.tweets_buffer)) if len(self.tweets_buffer) >= self.buffer_size: Tweet.objects.bulk_create(self.tweets_buffer) del self.tweets_buffer[:] print 'INFO: Bulk created 100 tweets %s' % timezone.now() except KeyError: print 'INFO: Error message %s' % status