<commit_before>from coinmarketcap import Market
from currency_converter import CurrencyConverter

fiat_currencies = {
    'AUD': '$', 'BRL': 'R$', 'CAD': '$', 'CHF': 'Fr.',
    'CLP': '$', 'CNY': '¥', 'CZK': 'Kc', 'DKK': 'kr',
    'EUR': '€', 'GBP': '£', 'HKD': 'HK$', 'HUF': 'Ft',
    'IDR': 'Rp ', 'ILS': '₪', 'INR': '₹', 'JPY': '¥‎',
    'KRW': '₩', 'MXN': '$', 'MYR': 'RM', 'NOK': 'kr',
    'NZD': '$', 'PHP': '₱', 'PKR': 'Rupees', 'PLN': 'zł',
    'RUB': '₽', 'SEK': 'kr', 'SGD': 'S$', 'THB': '฿',
    'TRY': '₺', 'TWD': 'NT$', 'ZAR': 'R ', 'USD': '$'
}

fiat_suffix = [
    'CZK', 'DKK', 'HUF',
    'NOK', 'PKR', 'RUB',
    'SEK'
]


class CurrencyException(Exception):
    """Exception class for invalid currencies"""


class CoinMarketException(Exception):
    """Exception class for CoinMarket"""


class FiatException(Exception):
    """Exception class for invalid fiat"""


class MarketStatsException(Exception):
    """Exception class for invalid retrieval of market stats"""


class CoinMarket:
    """Handles CoinMarketCap API features"""

    def __init__(self):
        """
        Initiates CoinMarket

        @param bot - discord bot object
        """
        self.market = Market()

    def fiat_check(self, fiat):
        """
        Checks if fiat is valid. If invalid, raise FiatException error.

        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @return - uppercase fiat
        """
        if fiat is not fiat.upper():
            fiat = fiat.upper()
        if fiat not in fiat_currencies:
            error_msg = "This fiat currency is not supported: `{}`".format(fiat)
            raise FiatException(error_msg)
        return fiat

    def format_price(self, price, fiat, symbol=True):
        """
        Formats price under the desired fiat

        @param price - price to format
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @param symbol - if True add currency symbol to fiat
                        if False symbol will not be added
        @return - formatted price under fiat
        """
        c = CurrencyConverter()
        ucase_fiat = fiat.upper()
        if fiat is not "USD":
            price = float(c.convert(float(price), "USD", fiat))
        if symbol:
            if ucase_fiat in fiat_suffix:
                formatted_fiat = "{:,.6f} {}".format(float(price),
                                                     fiat_currencies[ucase_fiat])
            else:
                formatted_fiat = "{}{:,.6f}".format(fiat_currencies[ucase_fiat],
                                                    float(price))
        else:
            formatted_fiat = str(price)
        formatted_fiat = formatted_fiat.rstrip('0')
        if formatted_fiat.endswith('.'):
            formatted_fiat = formatted_fiat.replace('.', '')
        return formatted_fiat

    def fetch_currency_data(self, currency="", fiat="", load_all=False):
        """
        Fetches the currency data based on the desired currency

        @param currency - the cryptocurrency to search for (i.e. 'bitcoin',
                          'ethereum')
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @param load_all - True: load all cryptocurrencies
                          False: don't load all cryptocurrencies
        @return - currency data
        """
        try:
            if load_all:
                return self.market.ticker(start=0, limit=0)
            return self.market.ticker(currency, convert=fiat)
        except Exception as e:
            raise CurrencyException("Failed to find currency: `{}`. Check "
                                    "if this currency is valid and also check "
                                    "for spelling errors.".format(currency))

    def _format_currency_data(self, data, fiat):
        """
        Formats the data fetched

        @param currency - the cryptocurrency to search for (i.e. 'bitcoin',
                          'ethereum')
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @return - formatted currency data
        """
        try:
            price = CurrencyConverter()
            isPositivePercent = True
            formatted_data = ''
            hour_trend = ''
            if float(data['percent_change_24h']) >= 0:
                hour_trend = '<:small_green_triangle:396586561413578752>'
            else:
                hour_trend = ':small_red_triangle_down:'
                isPositivePercent = False

            formatted_data += '__**#{}. {} ({})**__ {}\n'.format(data['rank'],
                                                                 data['name'],
                                                                 data['symbol'],
                                                                 hour_trend)
            if fiat is not "USD":
                converted_price = float(price.convert(float(data['price_usd']),
                                                      'USD',
                                                      fiat))
            converted_price = "{:,.6f}".format(converted_price).rstrip('0')
            if converted_price.endswith('.'):
                converted_price = converted_price.replace('.', '')
            if fiat in fiat_suffix:
                formatted_data += 'Price ({}): **{} {}**\n\n'.format(fiat,
                                                                     converted_price,
                                                                     fiat_currencies[fiat])
            else:
                formatted_data += 'Price ({}): **{}{}**\n\n'.format(fiat,
                                                                    fiat_currencies[fiat],
                                                                    converted_price)
            formatted_data += 'Price (BTC): **{:,}**\n\n'.format(float(data['price_btc']))
            if (data['market_cap_usd'] is None):
                formatted_data += 'Market Cap ({}): Unknown\n\n'.format(fiat)
            else:
                converted_price = float(price.convert(float(data['market_cap_usd']),
                                                      'USD',
                                                      fiat))
                formatted_data += 'Market Cap ({}): **${:,}**\n\n'.format(fiat,
                                                                          converted_price)
            if (data['available_supply'] is None):
                formatted_data += 'Available Supply: Unknown\n\n'
            else:
                formatted_data += 'Available Supply: **{:,}**\n\n'.format(float(data['available_supply']))<commit_msg>Tweaked message layout once again<commit_after>from coinmarketcap import Market
from currency_converter import CurrencyConverter

fiat_currencies = {
    'AUD': '$', 'BRL': 'R$', 'CAD': '$', 'CHF': 'Fr.',
    'CLP': '$', 'CNY': '¥', 'CZK': 'Kc', 'DKK': 'kr',
    'EUR': '€', 'GBP': '£', 'HKD': 'HK$', 'HUF': 'Ft',
    'IDR': 'Rp ', 'ILS': '₪', 'INR': '₹', 'JPY': '¥‎',
    'KRW': '₩', 'MXN': '$', 'MYR': 'RM', 'NOK': 'kr',
    'NZD': '$', 'PHP': '₱', 'PKR': 'Rupees', 'PLN': 'zł',
    'RUB': '₽', 'SEK': 'kr', 'SGD': 'S$', 'THB': '฿',
    'TRY': '₺', 'TWD': 'NT$', 'ZAR': 'R ', 'USD': '$'
}

fiat_suffix = [
    'CZK', 'DKK', 'HUF',
    'NOK', 'PKR', 'RUB',
    'SEK'
]


class CurrencyException(Exception):
    """Exception class for invalid currencies"""


class CoinMarketException(Exception):
    """Exception class for CoinMarket"""


class FiatException(Exception):
    """Exception class for invalid fiat"""


class MarketStatsException(Exception):
    """Exception class for invalid retrieval of market stats"""


class CoinMarket:
    """Handles CoinMarketCap API features"""

    def __init__(self):
        """
        Initiates CoinMarket

        @param bot - discord bot object
        """
        self.market = Market()

    def fiat_check(self, fiat):
        """
        Checks if fiat is valid. If invalid, raise FiatException error.

        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @return - uppercase fiat
        """
        if fiat is not fiat.upper():
            fiat = fiat.upper()
        if fiat not in fiat_currencies:
            error_msg = "This fiat currency is not supported: `{}`".format(fiat)
            raise FiatException(error_msg)
        return fiat

    def format_price(self, price, fiat, symbol=True):
        """
        Formats price under the desired fiat

        @param price - price to format
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @param symbol - if True add currency symbol to fiat
                        if False symbol will not be added
        @return - formatted price under fiat
        """
        c = CurrencyConverter()
        ucase_fiat = fiat.upper()
        if fiat is not "USD":
            price = float(c.convert(float(price), "USD", fiat))
        if symbol:
            if ucase_fiat in fiat_suffix:
                formatted_fiat = "{:,.6f} {}".format(float(price),
                                                     fiat_currencies[ucase_fiat])
            else:
                formatted_fiat = "{}{:,.6f}".format(fiat_currencies[ucase_fiat],
                                                    float(price))
        else:
            formatted_fiat = str(price)
        formatted_fiat = formatted_fiat.rstrip('0')
        if formatted_fiat.endswith('.'):
            formatted_fiat = formatted_fiat.replace('.', '')
        return formatted_fiat

    def fetch_currency_data(self, currency="", fiat="", load_all=False):
        """
        Fetches the currency data based on the desired currency

        @param currency - the cryptocurrency to search for (i.e. 'bitcoin',
                          'ethereum')
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @param load_all - True: load all cryptocurrencies
                          False: don't load all cryptocurrencies
        @return - currency data
        """
        try:
            if load_all:
                return self.market.ticker(start=0, limit=0)
            return self.market.ticker(currency, convert=fiat)
        except Exception as e:
            raise CurrencyException("Failed to find currency: `{}`. Check "
                                    "if this currency is valid and also check "
                                    "for spelling errors.".format(currency))

    def _format_currency_data(self, data, fiat):
        """
        Formats the data fetched

        @param currency - the cryptocurrency to search for (i.e. 'bitcoin',
                          'ethereum')
        @param fiat - desired fiat currency (i.e. 'EUR', 'USD')
        @return - formatted currency data
        """
        try:
            price = CurrencyConverter()
            isPositivePercent = True
            formatted_data = ''
            hour_trend = ''
            if float(data['percent_change_24h']) >= 0:
                hour_trend = '<:small_green_triangle:396586561413578752>'
            else:
                hour_trend = ':small_red_triangle_down:'
                isPositivePercent = False

            formatted_data += '__**#{}. {} ({})**__ {}\n'.format(data['rank'],
                                                                 data['name'],
                                                                 data['symbol'],
                                                                 hour_trend)
            if fiat is not "USD":
                converted_price = float(price.convert(float(data['price_usd']),
                                                      'USD',
                                                      fiat))
            converted_price = "{:,.6f}".format(converted_price).rstrip('0')
            if converted_price.endswith('.'):
                converted_price = converted_price.replace('.', '')
            if fiat in fiat_suffix:
                formatted_data += 'Price ({}): **{} {}**\n'.format(fiat,
                                                                   converted_price,
                                                                   fiat_currencies[fiat])
            else:
                formatted_data += 'Price ({}): **{}{}**\n'.format(fiat,
                                                                    fiat_currencies[fiat],
                                                                    converted_price)
            formatted_data += 'Price (BTC): **{:,}**\n\n'.format(float(data['price_btc']))
            if (data['market_cap_usd'] is None):
                formatted_data += 'Market Cap ({}): Unknown\n'.format(fiat)
            else:
                converted_price = float(price.convert(float(data['market_cap_usd']),
                                                      'USD',
                                                      fiat))
                formatted_data += 'Market Cap ({}): **${:,}**\n'.format(fiat,
                                                                        converted_price)
            if (data['available_supply'] is None):
                formatted_data += 'Available Supply: Unknown\n\n'
            else:
                formatted_data += 'Available Supply: **{:,}**\n\n'.format(float(data['available_supply']))
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.004204204204204204, 'mean_word_length': 1.4829450139794966, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 68, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92150', 'n_tokens_mistral': 3791, 'n_tokens_neox': 3542, 'n_words': 895}