def test_feature_vector(self):

        tweet = {}

        tweet[
            'text'] = "This is a test #bla @rkempter Sommerferien and Lorem Ipsum"

        tweet['entities'] = {}
        tweet['entities']['hashtags'] = [{"text": "bla"}, {"text": "blu"}]
        tweet['entities']['urls'] = [{
            "expanded_url": "http://www.twitter.com"
        }]
        tweet['entities']['user_mentions'] = [{"id": "1111"}, {"id": "2222"}]
        tweet['user'] = {"str_id": "1111"}

        trainer = AdaptiveTweetClassifierTrainer(self.q)

        trainer.query_set = {}
        trainer.query_set['keyword'] = ["Sommerferien", "blu", "empty", "leer"]
        trainer.query_set['user'] = ["2222", "3333"]

        vector = trainer.get_feature_vector(tweet)
        real_vector = [1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.2222222222222222]

        self.assertEqual(vector, real_vector)
    def test_feature_vector(self):

        tweet = {}

        tweet["text"] = "This is a test #bla @rkempter Sommerferien and Lorem Ipsum"

        tweet["entities"] = {}
        tweet["entities"]["hashtags"] = [{"text": "bla"}, {"text": "blu"}]
        tweet["entities"]["urls"] = [{"expanded_url": "http://www.twitter.com"}]
        tweet["entities"]["user_mentions"] = [{"id": "1111"}, {"id": "2222"}]
        tweet["user"] = {"str_id": "1111"}

        trainer = AdaptiveTweetClassifierTrainer(self.q)

        trainer.query_set = {}
        trainer.query_set["keyword"] = ["Sommerferien", "blu", "empty", "leer"]
        trainer.query_set["user"] = ["2222", "3333"]

        vector = trainer.get_feature_vector(tweet)
        real_vector = [1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.2222222222222222]

        self.assertEqual(vector, real_vector)
            cursor.close()
            self.connection.commit()
        except Exception as inst:
            print type(inst)     # the exception instance
            print inst.args      # arguments stored in .args
            print inst           # __str__ allows args to printed directly

        if not self.queue.empty():
            self.classifier = self.queue.get()
            return False # force a restart of the stream
        else:
            return True

    def on_error(self, status):
        print status

if __name__ == '__main__':
    query_set = dict()
    query_set['keyword'] = ['obama', 'usa']
    query_set['user'] = ['326698989', '326802887', '314575095', '16573941', '15033883']
    queue = Queue.Queue()
    trainer = AdaptiveTweetClassifierTrainer(queue)
    l = TweetStreamListener(trainer, queue)
    auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    stream = Stream(auth, l)

    while True:
        stream.filter(follow=query_set['user'], track=query_set['keyword'])
        query_set = trainer.get_query_set()
        print "Model loading"