コード例 #1
0
class TwitterWorker(DataStreamAbstract):
    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()

    def run(self):
        logger.info("started %s", self.getName())

        while True:
            if self.terminate.isSet():
                logger.info("Terminated")
                return None

            try:
                self.check_keywords()
                self.stream.connect(self.kw_track)
                self.get_tweets()

            except TwitterWorkerKwChange, e:
                logger.info(e.message)

            except TwitterWorkerKwEmpty, e:
                sleep_int = config.twitter_kw_interval_check / 2
                logger.warn("%s - sleeping for %d sec", e.message, sleep_int)
                time.sleep(sleep_int)

            except TwitterStreamHttpException, e:
                logger.warn("%s - sleeping for %d sec", e.message,
                            config.twitter_http_error_sleep)
                time.sleep(config.twitter_http_error_sleep)
コード例 #2
0
class TwitterWorker(DataStreamAbstract):
    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()

    def run(self):
        logger.info("started %s", self.getName())

        while True:
            if self.terminate.isSet():
                logger.info("Terminated")
                return None

            try:
                self.check_keywords()
                self.stream.connect(self.kw_track)
                self.get_tweets()

            except TwitterWorkerKwChange, e:
                logger.info(e.message)

            except TwitterWorkerKwEmpty, e:
                sleep_int = config.twitter_kw_interval_check / 2
                logger.warn("%s - sleeping for %d sec", e.message, sleep_int)
                time.sleep(sleep_int)

            except TwitterStreamHttpException, e:
                logger.warn("%s - sleeping for %d sec", e.message, config.twitter_http_error_sleep)
                time.sleep(config.twitter_http_error_sleep)
コード例 #3
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()
コード例 #4
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()