Example #1
0
def stui_main(ctxt=None,
              stui_name='stui',
              stui_id=None,
              discovery_addr='localhost:5555',
              mgmt_addr='localhost:6666',
              poll_timeout=5000,
              log_cfg='../conf/logconf_stui.json'):
    try:
        event = None

        if (log_cfg is None):
            log_cfg = '../conf/logconf_stui.json'

        initlog(log_cfg)

        logger = logging.getLogger()

        t, event = init_stui(ctxt, stui_name, stui_id, discovery_addr,
                             mgmt_addr, poll_timeout, log_cfg)

        while t.is_alive() is True:
            t.join(timeout=1.0)
    except KeyboardInterrupt:
        logger.info('Shutting Down...')
        if (event is not None):
            event.set()
            t.join()
    except:
        logger.exception('Shutting Down...')
        if (event is not None):
            event.set()
            t.join()
Example #2
0
def init_stmgr(ctxt=None,
               stmgr_name='stmgr',
               stmgr_id=None,
               discovery_addr='*:5555',
               mgmt_addr='*:6666',
               discovery_interval=5,
               poll_timeout=5000,
               log_cfg='../conf/logconf_stmgr.json'):
    func_name = init_stmgr.__name__
    try:
        initstmsg()

        if(ctxt is None):
            ctxt = zmq.Context()

        if(stmgr_name is None):
            stmgr_name = 'stmgr'

        if(discovery_addr is None):
            discovery_addr = '*:5555'

        if(mgmt_addr is None):
            mgmt_addr = '*:6666'

        if(discovery_interval is None):
            discovery_interval = 5

        if(poll_timeout is None):
            poll_timeout = 5000

        if(log_cfg is None):
            log_cfg = '../conf/logconf_stmgr.json'

        initlog(log_cfg)

        logger = logging.getLogger()

        shutdown_event = threading.Event()

        args = (shutdown_event, ctxt, stmgr_name,
                stmgr_id, discovery_addr,
                mgmt_addr, discovery_interval, poll_timeout)

        stmgr_thread = threading.Thread(target=stmgr_loop,
                                        args=args)

        stmgr_thread.start()

        return stmgr_thread, shutdown_event
    except:
        logger.exception('%s : stmgr initialization failed...',
                         func_name)
Example #3
0
def init_stmgr(ctxt=None,
               stmgr_name='stmgr',
               stmgr_id=None,
               discovery_addr='*:5555',
               mgmt_addr='*:6666',
               discovery_interval=5,
               poll_timeout=5000,
               log_cfg='../conf/logconf_stmgr.json'):
    func_name = init_stmgr.__name__
    try:
        initstmsg()

        if (ctxt is None):
            ctxt = zmq.Context()

        if (stmgr_name is None):
            stmgr_name = 'stmgr'

        if (discovery_addr is None):
            discovery_addr = '*:5555'

        if (mgmt_addr is None):
            mgmt_addr = '*:6666'

        if (discovery_interval is None):
            discovery_interval = 5

        if (poll_timeout is None):
            poll_timeout = 5000

        if (log_cfg is None):
            log_cfg = '../conf/logconf_stmgr.json'

        initlog(log_cfg)

        logger = logging.getLogger()

        shutdown_event = threading.Event()

        args = (shutdown_event, ctxt, stmgr_name, stmgr_id, discovery_addr,
                mgmt_addr, discovery_interval, poll_timeout)

        stmgr_thread = threading.Thread(target=stmgr_loop, args=args)

        stmgr_thread.start()

        return stmgr_thread, shutdown_event
    except:
        logger.exception('%s : stmgr initialization failed...', func_name)
Example #4
0
def stsvc_main(ctxt=None,
               stsvc_name='stsvc',
               stsvc_id=None,
               discovery_addr='localhost:5555',
               mgmt_addr='localhost:6666',
               inproc_addr_list=None,
               inproc_shutdown_event_list=None,
               poll_timeout=5000,
               log_cfg='../conf/logconf_stsvc.json'):
    try:
        event = None

        if(log_cfg is None):
            log_cfg = '../conf/logconf_stsvc.json'

        initlog(log_cfg)

        logger = logging.getLogger()

        t, event = init_stsvc(ctxt,
                              stsvc_name,
                              stsvc_id,
                              discovery_addr,
                              mgmt_addr,
                              inproc_addr_list,
                              inproc_shutdown_event_list,
                              poll_timeout,
                              log_cfg)

        while t.is_alive() is True:
            t.join(timeout=1.0)
    except KeyboardInterrupt:
        logger.info('Shutting Down...')
        if(event is not None):
            event.set()
            t.join()
    except:
        logger.exception('Shutting Down...')
        if(event is not None):
            event.set()
            t.join()
Example #5
0
def stmgr_main(ctxt=None,
               stmgr_name='stmgr',
               stmgr_id=None,
               discovery_addr='*:5555',
               mgmt_addr='*:6666',
               discovery_interval=5,
               poll_timeout=5000,
               log_cfg='../conf/logconf_stmgr.json'):
    try:
        event = None

        if(log_cfg is None):
            log_cfg = '../conf/logconf_stmgr.json'

        initlog(log_cfg)

        logger = logging.getLogger()

        t, event = init_stmgr(ctxt,
                              stmgr_name,
                              stmgr_id,
                              discovery_addr,
                              mgmt_addr,
                              discovery_interval,
                              poll_timeout,
                              log_cfg)

        while t.is_alive() is True:
            t.join(timeout=1.0)
    except KeyboardInterrupt:
        logger.info('Shutting Down...')
        if(event is not None):
            event.set()
            t.join()
    except:
        logger.exception('Shutting Down...')
        if(event is not None):
            event.set()
            t.join()
Example #6
0
from utils.request import HttpRequest
from utils import xmljson
from utils import log


class RequestAPI:
    def __init__(self):
        self.hr = HttpRequest()
        self.home = 'http://s.weibo.com/'
        self.url_search_comment = 'wb/%s'

    def search_comment(self, keyword, offset=0, sort='hot'):
        _url = '%s/%s' % (self.home, self.url_search_comment % keyword)
        _ret = self.hr.get(_url, {
            'offset': offset,
            'xsort': sort,
            'scope': 'ori',
            'page': offset
        })
        logging.debug('search result:%s' % _ret)

        return _ret


if __name__ == '__main__':
    log.initlog('', True)
    rapi = RequestAPI()

    print rapi.search_comment('百年孤独')
Example #7
0
        finally:
            self.dbHandler.disconnect()

        if _book is None:
            _book = self.requestAPI.get_book_by_isbn(str(isbn))  # ('9787532706907')
            
        return _book

    def get_book_reviews(self,id, offset=0, limit=5, orderby_time=False):
        _reviews = None
        _reviews = self.requestAPI.get_book_reviews(id, offset=offset, limit=limit, orderby_time=orderby_time)
        
        if _reviews is None:
            return {}
        return _reviews
        
    def get_ratings(self,id):
        _ratings = self.requestAPI.get_ratings(id)
        
        return _ratings
        
if __name__ == '__main__':
    log.initlog('', True)
    service = RequestService()
    service.search_books("百年孤独")
    print service.search_book_by_isbn('9787532706907')
    #pass
    print service.get_ratings(6082808)
    pass
Example #8
0
_lib_home = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_lib_home = os.path.normpath(_lib_home)

if not (_lib_home in sys.path):
    sys.path.insert(0, _lib_home)

from utils.request import HttpRequest
from utils import xmljson
from utils import log


class RequestAPI:
    def __init__(self):
        self.hr = HttpRequest()
        self.home = "http://s.weibo.com/"
        self.url_search_comment = "wb/%s"

    def search_comment(self, keyword, offset=0, sort="hot"):
        _url = "%s/%s" % (self.home, self.url_search_comment % keyword)
        _ret = self.hr.get(_url, {"offset": offset, "xsort": sort, "scope": "ori", "page": offset})
        logging.debug("search result:%s" % _ret)

        return _ret


if __name__ == "__main__":
    log.initlog("", True)
    rapi = RequestAPI()

    print rapi.search_comment("百年孤独")