Esempio n. 1
0
def main():
    # Set logging
    global log
    log = logging.getLogger(__name__)
    logging.basicConfig(
        format='%(asctime)s [%(levelname)s] %(message)s',
        level=logging.ERROR)

    # Parse command line arguments
    args = parse_arguments()

    # Enable verbose mode
    if args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    log.debug('START')

    # Instantiate the CyrrencyFair object
    cf = CurrencyFair(args.frm, args.to, args.amount, args.direction)
    keys = args.keys.split(',')

    values = None
    try:
        # Fetch the data from web
        values = cf.get_data(keys)
    except Exception as e:
        log.error('Can not get data: %s' % (e))
        sys.exit(1)

    # Print results
    for key, value in values.items():
        print('%s: %s' % (key, value))

    log.debug('END')
Esempio n. 2
0
    def read_callback(self, data=None):
        self.message('I', 'Reader callback...')

        for record in self.DATA:
            cf = CurrencyFair(
                record['from'],
                record['to'],
                record['amount'],
                record['direction'])

            values = None

            try:
                values = cf.get_data()
            except Exception as e:
                self.message('I', 'Can not get data: %s' % (e))
                break

            value = values['cfRate']
            if record['reciprocal'] == 'YES':
                value = "%0.4f" % (1 / float(value))

            self.message('I', "cfRate=%s (%s)" % (value, record['label']))

            metric = collectd.Values()
            metric.plugin = 'currencyfair'
            metric.plugin_instance = record['label']
            metric.type = 'gauge'
            metric.type_instance = 'cfrate'
            metric.values = [value]
            metric.dispatch()
Esempio n. 3
0
    def read_callback(self, data=None):
        self.message('I', 'Reader callback...')

        for record in self.DATA:
            cf = CurrencyFair(record['from'], record['to'], record['amount'],
                              record['direction'])

            values = None

            try:
                values = cf.get_data()
            except Exception as e:
                self.message('I', 'Can not get data: %s' % (e))
                break

            value = values['cfRate']
            if record['reciprocal'] == 'YES':
                value = "%0.4f" % (1 / float(value))

            self.message('I', "cfRate=%s (%s)" % (value, record['label']))

            metric = collectd.Values()
            metric.plugin = 'currencyfair'
            metric.plugin_instance = record['label']
            metric.type = 'gauge'
            metric.type_instance = 'cfrate'
            metric.values = [value]
            metric.dispatch()
Esempio n. 4
0
def main():
    # Set logging
    global log
    log = logging.getLogger(__name__)
    logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
                        level=logging.ERROR)

    # Parse command line arguments
    args = parse_arguments()

    # Enable verbose mode
    if args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    log.debug('START')

    # Instantiate the CyrrencyFair object
    cf = CurrencyFair(args.frm, args.to, args.amount, args.direction)
    keys = args.keys.split(',')

    values = None
    try:
        # Fetch the data from web
        values = cf.get_data(keys)
    except Exception as e:
        log.error('Can not get data: %s' % (e))
        sys.exit(1)

    # Print results
    for key, value in values.items():
        print('%s: %s' % (key, value))

    log.debug('END')