Example #1
0
    assert False, "expected KeyError"
except KeyError:
    pass

for idx in ('name', 'official_name', 'common_name'):
    index = pycountry.countries.indices[idx]
    for k in index.keys():
        index[k.upper()] = index[k]

# we should now be able to find both Palau and PALAU
assert find_country('Palau') is not None
assert find_country('PALAU') is not None

# search countries using py-moneyed data
from moneyed.classes import CURRENCIES
for cur_code, currency in CURRENCIES.iteritems():
    for country_name in currency.countries:
        try:
            cc = find_country(country_name)
            currencies = CC_TO_CURRENCIES.setdefault(str(cc), [])
            if cur_code not in currencies:
                print >> sys.stderr, "%s: %s augmenting hexorx data using py-moneyed" % (
                    cc, cur_code)
                currencies.append(str(cur_code))
        except KeyError:
            print >> sys.stderr, "cannot find country by the name of %s" % country_name
            continue

# Overrides based on some manual research (mostly Wikipedia)
OVERRIDES = {
    'WS': ('WST', ),  # http://en.wikipedia.org/wiki/Samoa