async def cmd_price(command_str, discord_message, apis):
    msg = ""
    # search through all exchanges, if the command contains a string in one of
    # exchanges command_names list, show only that exchange
    for exchange in apis.exchanges.all_exchanges:
        if util.string_contains_any(command_str,
                                    exchange.command_names,
                                    exhaustive_search=True,
                                    require_cmd_char=False):
            # skip CMC since it only tracks ETH and BTC price
            # skip LCW since its more of an aggregator
            if (exchange.exchange_name == "Coin Market Cap"
                or exchange.exchange_name == "Live Coin Watch"):
                continue
            return show_price_from_source(apis, source=exchange.exchange_name)
    if util.string_contains_any(command_str,
                                ['all', 'al', 'prices'],
                                exhaustive_search=True,
                                require_cmd_char=False):
        return await cmd_price_all(command_str, discord_message, apis)
    elif util.string_contains_any(command_str,
                             ['btc', 'bitcoin'],
                             exhaustive_search=True,
                             require_cmd_char=False):
        return await cmd_bitcoinprice(command_str, discord_message, apis)
    elif util.string_contains_any(command_str,
                             ['eth', 'ethereum'],
                             exhaustive_search=True,
                             require_cmd_char=False):
        return await cmd_ethereumprice(command_str, discord_message, apis)
    else:
        return show_price_from_source(apis)
async def handle_trading_command(command_str, discord_message, apis):
    msg = None

    # Check price comparision commands (defined in EXPENSIVE_STUFF in configuration.py)
    # TODO: move this into _TRADING_COMMANDS somehow
    for price, names in config.EXPENSIVE_STUFF:
        if util.string_contains_any(command_str,
                                    (name.lower() for name in names),
                                    exhaustive_search=True):
            correct_name = names[0]
            msg = await cmd_compare_price_vs(apis, correct_name, price)
            break

    if command_str[0] != config.COMMAND_CHARACTER:
        return None

    for cmd_def in config.TRADING_COMMANDS:
        if util.string_contains_any(command_str, cmd_def.keywords):
            if isinstance(cmd_def.response, str):
                return cmd_def.response
            else:
                return await cmd_def.response(command_str, discord_message,
                                              apis)

    return msg
Exemplo n.º 3
0
Arquivo: model.py Projeto: wmark/yars
	def matches(self, feeditem, case_sensitive):
		if case_sensitive:
			title, desired, unwanted = feeditem['title'], self.search_words, self.exclude_words
		else: # case-insensitive, the default
			title, desired, unwanted = feeditem['title'].lower(), self.search_words_lower, self.exclude_words_lower
		return         string_contains_all(title, desired) \
		       and not string_contains_any(title, unwanted)
Exemplo n.º 4
0
    def _set_optimizer(self):
        param_features = []
        param_classifiers = []

        def param_features_substring_list(architecture):
            for key in self._FEATURE_PARAM_LAYER_PATTERNS:
                if architecture.startswith(key):
                    return self._FEATURE_PARAM_LAYER_PATTERNS[key]
            raise KeyError("Fail to recognize the architecture {}"
                           .format(self.args.architecture))

        for name, parameter in self.model.named_parameters():
            if string_contains_any(
                    name,
                    param_features_substring_list(self.args.architecture)):
                if self.args.architecture in ('vgg16', 'inception_v3'):
                    param_features.append(parameter)
                elif self.args.architecture == 'resnet50':
                    param_classifiers.append(parameter)
            else:
                if self.args.architecture in ('vgg16', 'inception_v3'):
                    param_classifiers.append(parameter)
                elif self.args.architecture == 'resnet50':
                    param_features.append(parameter)

        optimizer = torch.optim.SGD([
            {'params': param_features, 'lr': self.args.lr},
            {'params': param_classifiers,
             'lr': self.args.lr * self.args.lr_classifier_ratio}],
            momentum=self.args.momentum,
            weight_decay=self.args.weight_decay,
            nesterov=True)
        return optimizer
async def handle_global_command(command_str, discord_message, apis):
    if command_str[0] != config.COMMAND_CHARACTER:
        return None

    for cmd_def in config.GLOBAL_COMMANDS:
        if util.string_contains_any(command_str, cmd_def.keywords):
            if isinstance(cmd_def.response, str):
                return cmd_def.response
            else:
                return await cmd_def.response(command_str, discord_message,
                                              apis)
    return None
def convert(amount, src, dest, apis):
    src = src.lower()
    dest = dest.lower()
    amount = string_to_float(amount)

    usd_value, result = None, None

    token_price_usd = apis.exchanges.price_eth(config.TOKEN_SYMBOL) * apis.exchanges.eth_price_usd()

    if config.TOKEN_SYMBOL != "0xBTC":
        logging.warning("unknown currency {}; !convert command assumes 0xBTC".format(config.TOKEN_SYMBOL))

    if src in ['0xbtc', '0xbitcoins', '0xbitcoin']:
        usd_value = token_price_usd * amount
    elif src in ['m0xbtc', 'milli0xbtc', 'milli0xbitcoin', 'milli0xbitcoins']:
        usd_value = token_price_usd * amount / 1000.0
    elif src in ['0xsatoshis', '0xsatoshi', 'satoastis', 'satoasti', 'crumbs', 'crumb']:
        usd_value = token_price_usd * amount / 10**8
    elif src in ['eth', 'ethereum', 'ether']:
        usd_value = apis.exchanges.eth_price_usd() * amount
    elif src == 'wei':
        usd_value = apis.exchanges.eth_price_usd() * amount / 10**18
    elif src in ['btc', 'bitcoins', 'bitcoin']:
        usd_value = apis.exchanges.btc_price_usd() * amount
    elif src in ['mbtc', 'millibtc', 'millibitcoins', 'millibitcoin']:
        usd_value = apis.exchanges.btc_price_usd() * amount / 1000.0
    elif src in ['satoshis', 'satoshi']:
        usd_value = apis.exchanges.btc_price_usd() * amount / 10**8
    elif src in ['usd', 'dollars', 'dollar', 'ddollar', 'bucks', 'buck']:
        usd_value = amount
    elif src in ['cents', 'cent']:
        usd_value = amount / 100.0
    else:
        for price, names in config.EXPENSIVE_STUFF:
            if util.string_contains_any(src, names, exhaustive_search=True, require_cmd_char=False):
                src = names[0]  # replace name with the non-typo'd version
                usd_value = amount * price
                break

    if usd_value == None:
        return "Bad currency ({}). 0xbtc, 0xsatoshis, eth, wei, btc, mbtc, satoshis, and usd are supported.".format(src)

    if dest in ['0xbtc', '0xbitcoins', '0xbitcoin']:
        result = usd_value / token_price_usd
    elif dest in ['m0xbtc', 'milli0xbtc', 'milli0xbitcoin', 'milli0xbitcoins']:
        result = 1000.0 * usd_value / token_price_usd
    elif dest in ['0xsatoshis', '0xsatoshi', 'satoastis', 'satoasti', 'crumbs', 'crumb']:
        result = 10**8 * usd_value / token_price_usd
    elif dest in ['eth', 'ethereum', 'ether']:
        result = usd_value / apis.exchanges.eth_price_usd()
    elif dest == 'wei':
        result = 10**18 * usd_value / apis.exchanges.eth_price_usd()
    elif dest in ['btc', 'bitcoins', 'bitcoin']:
        result = usd_value / apis.exchanges.btc_price_usd()
    elif dest in ['mbtc', 'millibtc', 'millibitcoins', 'millibitcoin']:
        result = usd_value * 1000.0 / apis.exchanges.btc_price_usd()
    elif dest in ['satoshis', 'satoshi']:
        result = 10**8 * usd_value / apis.exchanges.btc_price_usd()
    elif dest in ['usd', 'dollars', 'dollar', 'ddollar', 'bucks', 'buck']:
        result = usd_value
    elif dest in ['cents', 'cent']:
        result = usd_value * 100.0
    else:
        for price, names in config.EXPENSIVE_STUFF:
            if util.string_contains_any(dest, names, exhaustive_search=True, require_cmd_char=False):
                dest = names[0]  # replaces provided name with the non-typo'd version
                result = usd_value / price
                break

    if result == None:
        return "Bad currency ({}). 0xbtc, 0xsatoshis, eth, wei, btc, mbtc, satoshis, and usd are supported.".format(dest)

    amount = prettify_decimals(amount)
    result = prettify_decimals(result)

    return "{} {} = **{}** {}".format(amount, src, result, dest)