Ejemplo n.º 1
0
class ZmqPipeline(object):
    def open_spider(self, spider):
        if hasattr(spider, 'zmq'):
            try:
                from utils.api import MessageSender
                uri = spider.zmq
                log.msg('connect <{}>'.format(uri))
                self.sender = MessageSender(uri)
                return
            except Exception as ex:
                log.err('cannot connect to zmq: {}'.format(ex))

        self.sender = None

    def process_item(self, item, spider):
        if self.sender:
            try:
                self.sender.send(item2post(item))
            except Exception as ex:
                traceback.print_exc()
        return item

    def close_spider(self, spider):
        if self.sender:
            log.msg('disconnect zmq')
            self.sender.term()
Ejemplo n.º 2
0
class ZmqPipeline(object):

    def open_spider(self, spider):
        if hasattr(spider, 'zmq'):
            try:
                from utils.api import MessageSender
                uri = spider.zmq
                log.msg('connect <{}>'.format(uri))
                self.sender = MessageSender(uri)
                return
            except Exception as ex:
                log.err('cannot connect to zmq: {}'.format(ex))

        self.sender = None

    def process_item(self, item, spider):
        if self.sender:
            try:
                self.sender.send(item2post(item))
            except Exception as ex:
                traceback.print_exc()
        return item

    def close_spider(self, spider):
        if self.sender:
            log.msg('disconnect zmq')
            self.sender.term()
Ejemplo n.º 3
0
    def open_spider(self, spider):
        if hasattr(spider, 'zmq'):
            try:
                from utils.api import MessageSender
                uri = spider.zmq
                log.msg('connect <{}>'.format(uri))
                self.sender = MessageSender(uri)
                return
            except Exception as ex:
                log.err('cannot connect to zmq: {}'.format(ex))

        self.sender = None
Ejemplo n.º 4
0
    def open_spider(self, spider):
        if hasattr(spider, 'zmq'):
            try:
                from utils.api import MessageSender
                uri = spider.zmq
                log.msg('connect <{}>'.format(uri))
                self.sender = MessageSender(uri)
                return
            except Exception as ex:
                log.err('cannot connect to zmq: {}'.format(ex))

        self.sender = None