Ejemplo n.º 1
0
def argument_value_convert(method, argument, value, rpc_version):
    if method in ('torrent-add', 'torrent-get', 'torrent-set'):
        args = constants.TORRENT_ARGS[method[-3:]]
    elif method in ('session-get', 'session-set'):
        args = constants.SESSION_ARGS[method[-3:]]
    else:
        return ValueError('Method "%s" not supported' % (method))
    if argument in args:
        info = args[argument]
        invalid_version = True
        while invalid_version:
            invalid_version = False
            replacement = None
            if rpc_version < info[1]:
                invalid_version = True
                replacement = info[3]
            if info[2] and info[2] <= rpc_version:
                invalid_version = True
                replacement = info[4]
            if invalid_version:
                if replacement:
                    logger.warning(
                        'Replacing requested argument "%s" with "%s".'
                        % (argument, replacement))
                    argument = replacement
                    info = args[argument]
                else:
                    raise ValueError(
                        'Method "%s" Argument "%s" does not exist in version %d.'
                        % (method, argument, rpc_version))
        return (argument, TR_TYPE_MAP[info[0]](value))
    else:
        raise ValueError('Argument "%s" does not exists for method "%s".',
                         (argument, method))
Ejemplo n.º 2
0
 def update_values(self, data):
     try:
         self.market_cap = data['Market_cap']
         self.average_volume = data['Average_volume']
         self.eps = data['EPS']
         self.short_ratio = data['Short_ratio']
         self.pe = data['PE']
         self.peg = data['PEG']
     except KeyError:
         logger.warning("Invalid company info for {}".format(self.ticker))
Ejemplo n.º 3
0
 def update_values(self, data):
     try:
         self.market_cap = data['Market_cap']
         self.average_volume = data['Average_volume']
         self.eps = data['EPS']
         self.short_ratio = data['Short_ratio']
         self.pe = data['PE']
         self.peg = data['PEG']
     except KeyError:
         logger.warning("Invalid company info for {}".format(self.ticker))
 def _convert_market_cap(cap):
     if cap is None:
         return None
     elif cap.endswith('B'):
         return float(cap[:-1]) * 1000000000
     elif cap.endswith('M'):
         return float(cap[:-1]) * 1000000
     else:
         logger.warning("Market cap does not end with B or M, {}".format(cap))
         return None
 def _convert_market_cap(cap):
     if cap is None:
         return None
     elif cap.endswith('B'):
         return float(cap[:-1]) * 1000000000
     elif cap.endswith('M'):
         return float(cap[:-1]) * 1000000
     else:
         logger.warning(
             "Market cap does not end with B or M, {}".format(cap))
         return None
Ejemplo n.º 6
0
 def update_values(self, data):
     try:
         self.open = data['Open']
         self.close = data['Close']
         self.high = data['High']
         self.low = data['Low']
         self.volume = data['Volume']
         self.save()
     except TypeError as e:
         logger.warning("Error while updating values for {}, {}".format(self.ticker.ticker, e))
     except KeyError as e:
         logger.warning("Error while updating values for {}, {}".format(self.ticker.ticker, e))
Ejemplo n.º 7
0
 def update_values(self, data):
     try:
         self.open = data['Open']
         self.close = data['Close']
         self.high = data['High']
         self.low = data['Low']
         self.volume = data['Volume']
         self.save()
     except TypeError as e:
         logger.warning("Error while updating values for {}, {}".format(
             self.ticker.ticker, e))
     except KeyError as e:
         logger.warning("Error while updating values for {}, {}".format(
             self.ticker.ticker, e))
Ejemplo n.º 8
0
    def start_http_server(self, port=80):
        """Starts a simple http server on a choosen port.

        :port: integer defaults to 80
        """
        if (self.__http is None):
            cmd = "python -m SimpleHTTPServer %d" % port
            try:
                self.__http = Popen(cmd, shell=True, preexec_fn=setsid)
                logger.info('HMI%d - HTTP server started on port %d' %
                            (self.__id, port))

            except OSError as e:
                emsg = repr(e)
                logger.warning('HMI%d - HTTP server cannot start: %s' %
                               (self.__id, emsg))
Ejemplo n.º 9
0
    start_time = time.time()

    while (time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]
        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
            logger.warning("PLC1 - lit101 over HH: %.2f >= %.2f" %
                           (lit101, LIT_101['HH']))

        elif lit101 <= LIT_101['LL']:
            logger.warning("PLC1 - lit101 under LL: %.2f <= %.2f" %
                           (lit101, LIT_101['LL']))
            val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_P101-Status',
                             PLC1_CPPPO_CACHE)
            logger.info("PLC1 - p101 read HMI_P101-Status: %s" % val)

        elif lit101 <= LIT_101['L']:
            logger.warning("PLC1 - lit101 under L: %.2f <= %.2f" %
                           (lit101, LIT_101['L']))
            val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_MV101-Status',
                             PLC1_CPPPO_CACHE)
            logger.info("PLC1 - p101 read HMI_MV101-Status: %s" % val)
Ejemplo n.º 10
0
    start_time = time.time()

    while(time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]
        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
            logger.warning("PLC1 - lit101 over HH: %.2f >= %.2f" % (
                lit101, LIT_101['HH']))

        elif lit101 <= LIT_101['LL']:
            logger.warning("PLC1 - lit101 under LL: %.2f <= %.2f" % (
                lit101, LIT_101['LL']))
            val = read_cpppo(
                L1_PLCS_IP['plc1'], 'HMI_P101-Status', PLC1_CPPPO_CACHE)
            logger.info("PLC1 - p101 read HMI_P101-Status: %s" % val)

        elif lit101 <= LIT_101['L']:
            logger.warning("PLC1 - lit101 under L: %.2f <= %.2f" % (
                lit101, LIT_101['L']))
            val = read_cpppo(
                L1_PLCS_IP['plc1'], 'HMI_MV101-Status', PLC1_CPPPO_CACHE)
            logger.info("PLC1 - p101 read HMI_MV101-Status: %s" % val)
Ejemplo n.º 11
0
    start_time = time.time()

    while(time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]

        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
            logger.warning("PLC1 - lit101 over HH: %.2f >= %.2f" % (
                lit101, LIT_101['HH']))

        elif lit101 <= LIT_101['LL']:
            logger.warning("PLC1 - lit101 under LL: %.2f <= %.2f" % (
                lit101, LIT_101['LL']))
            # CLOSE p101
            update_statedb('0', 'DO_P_101_START')
            write_cpppo(L1_PLCS_IP['plc1'], 'HMI_P101-Status', '1')
            val = read_cpppo(
                L1_PLCS_IP['plc1'], 'HMI_P101-Status', PLC1_CPPPO_CACHE)
            logger.warning("PLC1 - close p101: HMI_P101-Status: %s" % val)

        elif lit101 <= LIT_101['L']:
            # OPEN mv101
            update_statedb('0', 'DO_MV_101_CLOSE')
            update_statedb('1', 'DO_MV_101_OPEN')