def __init__(self, terminate):
        DataStreamAbstract.__init__(self, terminate)
        self.stream = TwitterStreamHandler()

        self.kw_track = SocketSession.get_keywords()
        self.kw_hash = SocketSession.get_keywords_hash()
        self.kw_int = config.twitter_kw_interval_check
        self.kw_last_check = time.time()
Example #2
0
    def __init__(self, terminate):
        DataStreamAbstract.__init__(self, terminate)
        self.stream = TwitterStreamHandler()

        self.kw_track = SocketSession.get_keywords()
        self.kw_hash = SocketSession.get_keywords_hash()
        self.kw_int = config.twitter_kw_interval_check
        self.kw_last_check = time.time()
Example #3
0
    def __init__(self, terminate):
        DataStreamAbstract.__init__(self, terminate)

        self.auth = twitter.OAuth(config.twitter_oauth_token, config.twitter_oauth_secret,
                                  config.twitter_oauth_custkey, config.twitter_oauth_custsecret)

        self.kw_track = SocketSession.get_keywords()
        self.kw_hash = SocketSession.get_keywords_hash()
        self.kw_int = config.twitter_kw_interval_check
        self.kw_last_check = time.time()
    def check_keywords(self):
        """
        check if twitter keywords are changed
        """
        if (time.time() - self.kw_last_check) > self.kw_int:
            kw_hash = SocketSession.get_keywords_hash()

            if self.kw_hash != kw_hash:
                self.kw_hash = kw_hash
                self.kw_track = SocketSession.get_keywords()
                raise TwitterWorkerKwChange('keywords change detected')
Example #5
0
    def check_keywords(self):
        """
        check if twitter keywords are changed
        """
        if (time.time() - self.kw_last_check) > self.kw_int:
            kw_hash = SocketSession.get_keywords_hash()

            if self.kw_hash != kw_hash:
                self.kw_hash = kw_hash
                self.kw_track = SocketSession.get_keywords()
                raise TwitterWorkerKwChange('keywords change detected')
    def test_workerSleep(self):
        """
        twitter collector should sleep if not keywords found
        """
        RawStreamQueue.drop_collection()
        SocketSession.drop_collection()
        kill = threading.Event()

        self.assertEqual(len(SocketSession.get_keywords()), 0)
        w = TwitterWorker(kill)
        w.setDaemon(True)
        w.start()
        time.sleep(1)
        kill.set()
        self.assertEqual(RawStreamQueue.objects.count(), 0)
    def test_workerSleep(self):
        """
        twitter collector should sleep if not keywords found
        """
        RawStreamQueue.drop_collection()
        SocketSession.drop_collection()
        kill = threading.Event()

        self.assertEqual(len(SocketSession.get_keywords()),0)
        w = TwitterWorker(kill)
        w.setDaemon(True)
        w.start()
        time.sleep(1)
        kill.set()
        self.assertEqual(RawStreamQueue.objects.count(), 0)