Skip to content

Instantly share code, notes, and snippets.

@mjallday
Created August 12, 2011 09:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mjallday/1141751 to your computer and use it in GitHub Desktop.
Save mjallday/1141751 to your computer and use it in GitHub Desktop.
Tuple of currencies for Python
# -*- coding: utf-8 -*-
"""
list of currencies currently in circulation
taken from http://www.currency-iso.org/iso_index/iso_tables/iso_tables_a1.htm
http://www.iso.org/iso/currency_codes_list-1.html
2011-08-11
"""
CURRENCIES = ( ("AFN", "Afghani"),
("DZD", "Algerian Dinar"),
("ARS", "Argentine Peso"),
("AMD", "Armenian Dram"),
("AWG", "Aruban Guilder"),
("AUD", "Australian Dollar"),
("AZN", "Azerbaijanian Manat"),
("BSD", "Bahamian Dollar"),
("BHD", "Bahraini Dinar"),
("THB", "Baht"),
("PAB", "Balboa"),
("BBD", "Barbados Dollar"),
("BYR", "Belarussian Ruble"),
("BZD", "Belize Dollar"),
("BMD", "Bermudian Dollar"),
("VEF", "Bolivar Fuerte"),
("BOB", "Boliviano"),
("BRL", "Brazilian Real"),
("BND", "Brunei Dollar"),
("BGN", "Bulgarian Lev"),
("BIF", "Burundi Franc"),
("CAD", "Canadian Dollar"),
("CVE", "Cape Verde Escudo"),
("KYD", "Cayman Islands Dollar"),
("GHS", "Cedi"),
("CLP", "Chilean Peso"),
("COP", "Colombian Peso"),
("KMF", "Comoro Franc"),
("CDF", "Congolese Franc"),
("BAM", "Convertible Mark"),
("NIO", "Cordoba Oro"),
("CRC", "Costa Rican Colon"),
("HRK", "Croatian Kuna"),
("CUP", "Cuban Peso"),
("CZK", "Czech Koruna"),
("GMD", "Dalasi"),
("DKK", "Danish Krone"),
("MKD", "Denar"),
("DJF", "Djibouti Franc"),
("STD", "Dobra"),
("DOP", "Dominican Peso"),
("VND", "Dong"),
("XCD", "East Caribbean Dollar"),
("EGP", "Egyptian Pound"),
("SVC", "El Salvador Colon"),
("ETB", "Ethiopian Birr"),
("EUR", "Euro"),
("FKP", "Falkland Islands Pound"),
("FJD", "Fiji Dollar"),
("HUF", "Forint"),
("GIP", "Gibraltar Pound"),
("XAU", "Gold"),
("HTG", "Gourde"),
("PYG", "Guarani"),
("GNF", "Guinea Franc"),
("GYD", "Guyana Dollar"),
("HKD", "Hong Kong Dollar"),
("UAH", "Hryvnia"),
("ISK", "Iceland Krona"),
("INR", "Indian Rupee"),
("IRR", "Iranian Rial"),
("IQD", "Iraqi Dinar"),
("JMD", "Jamaican Dollar"),
("JOD", "Jordanian Dinar"),
("KES", "Kenyan Shilling"),
("PGK", "Kina"),
("LAK", "Kip"),
("KWD", "Kuwaiti Dinar"),
("MWK", "Kwacha"),
("AOA", "Kwanza"),
("MMK", "Kyat"),
("GEL", "Lari"),
("LVL", "Latvian Lats"),
("LBP", "Lebanese Pound"),
("ALL", "Lek"),
("HNL", "Lempira"),
("SLL", "Leone"),
("RON", "Leu"),
("LRD", "Liberian Dollar"),
("LYD", "Libyan Dinar"),
("SZL", "Lilangeni"),
("LTL", "Lithuanian Litas"),
("LSL", "Loti"),
("MGA", "Malagasy Ariary"),
("MYR", "Malaysian Ringgit"),
("MUR", "Mauritius Rupee"),
("MZN", "Metical"),
("MXN", "Mexican Peso"),
("MDL", "Moldovan Leu"),
("MAD", "Moroccan Dirham"),
("BOV", "Mvdol"),
("NGN", "Naira"),
("ERN", "Nakfa"),
("NAD", "Namibia Dollar"),
("NPR", "Nepalese Rupee"),
("ANG", "Netherlands Antillean Guilder"),
("ILS", "New Israeli Sheqel"),
("TMT", "New Manat"),
("TWD", "New Taiwan Dollar"),
("NZD", "New Zealand Dollar"),
("BTN", "Ngultrum"),
("KPW", "North Korean Won"),
("NOK", "Norwegian Krone"),
("PEN", "Nuevo Sol"),
("MRO", "Ouguiya"),
("PKR", "Pakistan Rupee"),
("XPD", "Palladium"),
("MOP", "Pataca"),
("TOP", "Pa’anga"),
("CUC", "Peso Convertible"),
("UYU", "Peso Uruguayo"),
("PHP", "Philippine Peso"),
("XPT", "Platinum"),
("GBP", "Pound Sterling"),
("BWP", "Pula"),
("QAR", "Qatari Rial"),
("GTQ", "Quetzal"),
("ZAR", "Rand"),
("OMR", "Rial Omani"),
("KHR", "Riel"),
("MVR", "Rufiyaa"),
("IDR", "Rupiah"),
("RUB", "Russian Ruble"),
("RWF", "Rwanda Franc"),
("SHP", "Saint Helena Pound"),
("SAR", "Saudi Riyal"),
("RSD", "Serbian Dinar"),
("SCR", "Seychelles Rupee"),
("XAG", "Silver"),
("SGD", "Singapore Dollar"),
("SBD", "Solomon Islands Dollar"),
("KGS", "Som"),
("SOS", "Somali Shilling"),
("TJS", "Somoni"),
("ZAR", "South African Rand"),
("LKR", "Sri Lanka Rupee"),
("XSU", "Sucre"),
("SDG", "Sudanese Pound"),
("SRD", "Surinam Dollar"),
("SEK", "Swedish Krona"),
("CHF", "Swiss Franc"),
("SYP", "Syrian Pound"),
("BDT", "Taka"),
("WST", "Tala"),
("TZS", "Tanzanian Shilling"),
("KZT", "Tenge"),
("TTD", "Trinidad and Tobago Dollar"),
("MNT", "Tugrik"),
("TND", "Tunisian Dinar"),
("TRY", "Turkish Lira"),
("AED", "UAE Dirham"),
("USD", "US Dollar"),
("UGX", "Uganda Shilling"),
("COU", "Unidad de Valor Real"),
("CLF", "Unidades de fomento"),
("UYI", "Uruguay Peso en Unidades Indexadas (URUIURUI)"),
("UZS", "Uzbekistan Sum"),
("VUV", "Vatu"),
("KRW", "Won"),
("YER", "Yemeni Rial"),
("JPY", "Yen"),
("CNY", "Yuan Renminbi"),
("ZMK", "Zambian Kwacha"),
("ZWL", "Zimbabwe Dollar"),
("PLN", "Zloty"),
)
#!/bin/python
from lxml import etree
HEADER = """ # -*- coding: utf-8 -*-
\"\"\"
list of currencies currently in circulation
taken from http://www.currency-iso.org/iso_index/iso_tables/iso_tables_a1.htm
http://www.iso.org/iso/currency_codes_list-1.html
http://www.currency-iso.org/dl_iso_table_a1.xml
2011-08-11
\"\"\"
CURRENCIES = ("""
output = codecs.open('currencies.py', 'w', 'utf-8')
invalid_codes = ['XUA', 'XBA', 'XBC', 'XBD', 'XBB', 'XOF',
'XPF', 'XAF', 'XTS', 'MXV', 'XDR', 'XXX',
'USN', 'USS', 'XFU', 'CHE', 'CHW']
currencies = []
tree = etree.ElementTree ( file='dl_iso_table_a1.xml')
cs = tree.findall ( "/ISO_CURRENCY" )
output.write(HEADER)
for item in cs:
# entity = item.findtext('ENTITY')
code = item.findtext('ALPHABETIC_CODE')
currency= item.findtext('CURRENCY')
if code not in invalid_codes:
currencies.append((code,currency))
for code, currency in sorted(set(currencies), key=lambda c: c[1]):
if not code:
continue
output.write('\t("%s", "%s"),\r\n' % (code, currency))
output.write(')\n')
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment