Exemplo n.º 1
0
def fetch():
    global stock
    config.logger.info("stock:fetch()")
    try:
        stock_semaphore.acquire(1)
        # fetch from server
        d = connection.getData(config.stock_url)
        config.logger.debug("stock: -> %s", d.status_code)
        j = d.json()
        if "success" in j and j["success"] and "result" in j and j["result"]:
            stock = j["result"]
            stock["retrieved"] = time.time()
            config.logger.debug("stock: -> retrieved")
            config.logger.debug("stock = %s" % stock)
            controller.reconnected()
            return True
        else:
            return False
    except Exception as e:
        import sys
        _, _, exc_tb = sys.exc_info()
        config.logger.error("stock: -> failure line %s: %s", exc_tb.tb_lineno,
                            e)
        #        import traceback
        #        tr=traceback.format_exc()
        #        aw = config.app_window
        #        aw.qmc.adderror(str(tr))
        #controller.disconnect(False) # don't disconnect on failure
        return False
    finally:
        if stock_semaphore.available() < 1:
            stock_semaphore.release(1)
Exemplo n.º 2
0
def fetch():
    global stock
    config.logger.info("stock:fetch()")
    try:
        stock_semaphore.acquire(1)
        # fetch from server
        d = connection.getData(config.stock_url)
        config.logger.debug("stock: -> %s", d.status_code)
        j = d.json()
        if "success" in j and j["success"] and "result" in j and j["result"]:
            stock = j["result"]
            stock["retrieved"] = time.time()
            config.logger.debug("stock: -> retrieved")
            config.logger.debug("stock = %s" % stock)
            controller.reconnected()
            return True
        else:
            return False
    except Exception as e:
        config.logger.error("stock: -> failure: %s", e)
        #controller.disconnect(False) # don't disconnect on failure
        return False
    finally:
        if stock_semaphore.available() < 1:
            stock_semaphore.release(1)