How to use the pycountry.currencies.lookup function in pycountry

To help you get started, we’ve selected a few pycountry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DOAJ / doaj / portality / datasets.py View on Github external
def get_currency_code(name):
    """ Retrieve a currency code by the currency name """
    try:
        return pycountry.currencies.lookup(name).alpha_3
    except LookupError:
        return None
github DOAJ / doaj / portality / datasets.py View on Github external
def get_currency_name(code):
    """ get the name of a currency from its code """
    try:
        cur = pycountry.currencies.lookup(code)
        return '{code} - {name}'.format(code=cur.alpha_3, name=cur.name)
    except LookupError:
        return code  # return what was passed in if not found