Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created September 1, 2012 06:48
Show Gist options
  • Save naiquevin/3565954 to your computer and use it in GitHub Desktop.
Save naiquevin/3565954 to your computer and use it in GitHub Desktop.
Various currencies in json format and code for scraping data and using it in KodeCRM
[
{
"symbol": "Lek",
"code": "ALL",
"uhex": [
"4c",
"65",
"6b"
],
"name": "Albania Lek"
},
{
"symbol": "\u060b",
"code": "AFN",
"uhex": [
"60b"
],
"name": "Afghanistan Afghani"
},
{
"symbol": "$",
"code": "ARS",
"uhex": [
"24"
],
"name": "Argentina Peso"
},
{
"symbol": "\u0192",
"code": "AWG",
"uhex": [
"192"
],
"name": "Aruba Guilder"
},
{
"symbol": "$",
"code": "AUD",
"uhex": [
"24"
],
"name": "Australia Dollar"
},
{
"symbol": "\u043c\u0430\u043d",
"code": "AZN",
"uhex": [
"43c",
"430",
"43d"
],
"name": "Azerbaijan New Manat"
},
{
"symbol": "$",
"code": "BSD",
"uhex": [
"24"
],
"name": "Bahamas Dollar"
},
{
"symbol": "$",
"code": "BBD",
"uhex": [
"24"
],
"name": "Barbados Dollar"
},
{
"symbol": "p.",
"code": "BYR",
"uhex": [
"70",
"2e"
],
"name": "Belarus Ruble"
},
{
"symbol": "BZ$",
"code": "BZD",
"uhex": [
"42",
"5a",
"24"
],
"name": "Belize Dollar"
},
{
"symbol": "$",
"code": "BMD",
"uhex": [
"24"
],
"name": "Bermuda Dollar"
},
{
"symbol": "$b",
"code": "BOB",
"uhex": [
"24",
"62"
],
"name": "Bolivia Boliviano"
},
{
"symbol": "KM",
"code": "BAM",
"uhex": [
"4b",
"4d"
],
"name": "Bosnia and Herzegovina Convertible Marka"
},
{
"symbol": "P",
"code": "BWP",
"uhex": [
"50"
],
"name": "Botswana Pula"
},
{
"symbol": "\u043b\u0432",
"code": "BGN",
"uhex": [
"43b",
"432"
],
"name": "Bulgaria Lev"
},
{
"symbol": "R$",
"code": "BRL",
"uhex": [
"52",
"24"
],
"name": "Brazil Real"
},
{
"symbol": "$",
"code": "BND",
"uhex": [
"24"
],
"name": "Brunei Darussalam Dollar"
},
{
"symbol": "\u17db",
"code": "KHR",
"uhex": [
"17db"
],
"name": "Cambodia Riel"
},
{
"symbol": "$",
"code": "CAD",
"uhex": [
"24"
],
"name": "Canada Dollar"
},
{
"symbol": "$",
"code": "KYD",
"uhex": [
"24"
],
"name": "Cayman Islands Dollar"
},
{
"symbol": "$",
"code": "CLP",
"uhex": [
"24"
],
"name": "Chile Peso"
},
{
"symbol": "\u00a5",
"code": "CNY",
"uhex": [
"a5"
],
"name": "China Yuan Renminbi"
},
{
"symbol": "$",
"code": "COP",
"uhex": [
"24"
],
"name": "Colombia Peso"
},
{
"symbol": "\u20a1",
"code": "CRC",
"uhex": [
"20a1"
],
"name": "Costa Rica Colon"
},
{
"symbol": "kn",
"code": "HRK",
"uhex": [
"6b",
"6e"
],
"name": "Croatia Kuna"
},
{
"symbol": "\u20b1",
"code": "CUP",
"uhex": [
"20b1"
],
"name": "Cuba Peso"
},
{
"symbol": "K\u010d",
"code": "CZK",
"uhex": [
"4b",
"10d"
],
"name": "Czech Republic Koruna"
},
{
"symbol": "kr",
"code": "DKK",
"uhex": [
"6b",
"72"
],
"name": "Denmark Krone"
},
{
"symbol": "RD$",
"code": "DOP",
"uhex": [
"52",
"44",
"24"
],
"name": "Dominican Republic Peso"
},
{
"symbol": "$",
"code": "XCD",
"uhex": [
"24"
],
"name": "East Caribbean Dollar"
},
{
"symbol": "\u00a3",
"code": "EGP",
"uhex": [
"a3"
],
"name": "Egypt Pound"
},
{
"symbol": "$",
"code": "SVC",
"uhex": [
"24"
],
"name": "El Salvador Colon"
},
{
"symbol": "kr",
"code": "EEK",
"uhex": [
"6b",
"72"
],
"name": "Estonia Kroon"
},
{
"symbol": "\u20ac",
"code": "EUR",
"uhex": [
"20ac"
],
"name": "Euro Member Countries"
},
{
"symbol": "\u00a3",
"code": "FKP",
"uhex": [
"a3"
],
"name": "Falkland Islands (Malvinas) Pound"
},
{
"symbol": "$",
"code": "FJD",
"uhex": [
"24"
],
"name": "Fiji Dollar"
},
{
"symbol": "\u00a2",
"code": "GHC",
"uhex": [
"a2"
],
"name": "Ghana Cedis"
},
{
"symbol": "\u00a3",
"code": "GIP",
"uhex": [
"a3"
],
"name": "Gibraltar Pound"
},
{
"symbol": "Q",
"code": "GTQ",
"uhex": [
"51"
],
"name": "Guatemala Quetzal"
},
{
"symbol": "\u00a3",
"code": "GGP",
"uhex": [
"a3"
],
"name": "Guernsey Pound"
},
{
"symbol": "$",
"code": "GYD",
"uhex": [
"24"
],
"name": "Guyana Dollar"
},
{
"symbol": "L",
"code": "HNL",
"uhex": [
"4c"
],
"name": "Honduras Lempira"
},
{
"symbol": "$",
"code": "HKD",
"uhex": [
"24"
],
"name": "Hong Kong Dollar"
},
{
"symbol": "Ft",
"code": "HUF",
"uhex": [
"46",
"74"
],
"name": "Hungary Forint"
},
{
"symbol": "kr",
"code": "ISK",
"uhex": [
"6b",
"72"
],
"name": "Iceland Krona"
},
{
"symbol": "\u20b9",
"code": "INR",
"uhex": [
"20b9"
],
"name": "India Rupee"
},
{
"symbol": "Rp",
"code": "IDR",
"uhex": [
"52",
"70"
],
"name": "Indonesia Rupiah"
},
{
"symbol": "\ufdfc",
"code": "IRR",
"uhex": [
"fdfc"
],
"name": "Iran Rial"
},
{
"symbol": "\u00a3",
"code": "IMP",
"uhex": [
"a3"
],
"name": "Isle of Man Pound"
},
{
"symbol": "\u20aa",
"code": "ILS",
"uhex": [
"20aa"
],
"name": "Israel Shekel"
},
{
"symbol": "J$",
"code": "JMD",
"uhex": [
"4a",
"24"
],
"name": "Jamaica Dollar"
},
{
"symbol": "\u00a5",
"code": "JPY",
"uhex": [
"a5"
],
"name": "Japan Yen"
},
{
"symbol": "\u00a3",
"code": "JEP",
"uhex": [
"a3"
],
"name": "Jersey Pound"
},
{
"symbol": "\u043b\u0432",
"code": "KZT",
"uhex": [
"43b",
"432"
],
"name": "Kazakhstan Tenge"
},
{
"symbol": "\u20a9",
"code": "KPW",
"uhex": [
"20a9"
],
"name": "Korea (North) Won"
},
{
"symbol": "\u20a9",
"code": "KRW",
"uhex": [
"20a9"
],
"name": "Korea (South) Won"
},
{
"symbol": "\u043b\u0432",
"code": "KGS",
"uhex": [
"43b",
"432"
],
"name": "Kyrgyzstan Som"
},
{
"symbol": "\u20ad",
"code": "LAK",
"uhex": [
"20ad"
],
"name": "Laos Kip"
},
{
"symbol": "Ls",
"code": "LVL",
"uhex": [
"4c",
"73"
],
"name": "Latvia Lat"
},
{
"symbol": "\u00a3",
"code": "LBP",
"uhex": [
"a3"
],
"name": "Lebanon Pound"
},
{
"symbol": "$",
"code": "LRD",
"uhex": [
"24"
],
"name": "Liberia Dollar"
},
{
"symbol": "Lt",
"code": "LTL",
"uhex": [
"4c",
"74"
],
"name": "Lithuania Litas"
},
{
"symbol": "\u0434\u0435\u043d",
"code": "MKD",
"uhex": [
"434",
"435",
"43d"
],
"name": "Macedonia Denar"
},
{
"symbol": "RM",
"code": "MYR",
"uhex": [
"52",
"4d"
],
"name": "Malaysia Ringgit"
},
{
"symbol": "\u20a8",
"code": "MUR",
"uhex": [
"20a8"
],
"name": "Mauritius Rupee"
},
{
"symbol": "$",
"code": "MXN",
"uhex": [
"24"
],
"name": "Mexico Peso"
},
{
"symbol": "\u20ae",
"code": "MNT",
"uhex": [
"20ae"
],
"name": "Mongolia Tughrik"
},
{
"symbol": "MT",
"code": "MZN",
"uhex": [
"4d",
"54"
],
"name": "Mozambique Metical"
},
{
"symbol": "$",
"code": "NAD",
"uhex": [
"24"
],
"name": "Namibia Dollar"
},
{
"symbol": "\u20a8",
"code": "NPR",
"uhex": [
"20a8"
],
"name": "Nepal Rupee"
},
{
"symbol": "\u0192",
"code": "ANG",
"uhex": [
"192"
],
"name": "Netherlands Antilles Guilder"
},
{
"symbol": "$",
"code": "NZD",
"uhex": [
"24"
],
"name": "New Zealand Dollar"
},
{
"symbol": "C$",
"code": "NIO",
"uhex": [
"43",
"24"
],
"name": "Nicaragua Cordoba"
},
{
"symbol": "\u20a6",
"code": "NGN",
"uhex": [
"20a6"
],
"name": "Nigeria Naira"
},
{
"symbol": "\u20a9",
"code": "KPW",
"uhex": [
"20a9"
],
"name": "Korea (North) Won"
},
{
"symbol": "kr",
"code": "NOK",
"uhex": [
"6b",
"72"
],
"name": "Norway Krone"
},
{
"symbol": "\ufdfc",
"code": "OMR",
"uhex": [
"fdfc"
],
"name": "Oman Rial"
},
{
"symbol": "\u20a8",
"code": "PKR",
"uhex": [
"20a8"
],
"name": "Pakistan Rupee"
},
{
"symbol": "B/.",
"code": "PAB",
"uhex": [
"42",
"2f",
"2e"
],
"name": "Panama Balboa"
},
{
"symbol": "Gs",
"code": "PYG",
"uhex": [
"47",
"73"
],
"name": "Paraguay Guarani"
},
{
"symbol": "S/.",
"code": "PEN",
"uhex": [
"53",
"2f",
"2e"
],
"name": "Peru Nuevo Sol"
},
{
"symbol": "\u20b1",
"code": "PHP",
"uhex": [
"20b1"
],
"name": "Philippines Peso"
},
{
"symbol": "z\u0142",
"code": "PLN",
"uhex": [
"7a",
"142"
],
"name": "Poland Zloty"
},
{
"symbol": "\ufdfc",
"code": "QAR",
"uhex": [
"fdfc"
],
"name": "Qatar Riyal"
},
{
"symbol": "lei",
"code": "RON",
"uhex": [
"6c",
"65",
"69"
],
"name": "Romania New Leu"
},
{
"symbol": "\u0440\u0443\u0431",
"code": "RUB",
"uhex": [
"440",
"443",
"431"
],
"name": "Russia Ruble"
},
{
"symbol": "\u00a3",
"code": "SHP",
"uhex": [
"a3"
],
"name": "Saint Helena Pound"
},
{
"symbol": "\ufdfc",
"code": "SAR",
"uhex": [
"fdfc"
],
"name": "Saudi Arabia Riyal"
},
{
"symbol": "\u0414\u0438\u043d.",
"code": "RSD",
"uhex": [
"414",
"438",
"43d",
"2e"
],
"name": "Serbia Dinar"
},
{
"symbol": "\u20a8",
"code": "SCR",
"uhex": [
"20a8"
],
"name": "Seychelles Rupee"
},
{
"symbol": "$",
"code": "SGD",
"uhex": [
"24"
],
"name": "Singapore Dollar"
},
{
"symbol": "$",
"code": "SBD",
"uhex": [
"24"
],
"name": "Solomon Islands Dollar"
},
{
"symbol": "S",
"code": "SOS",
"uhex": [
"53"
],
"name": "Somalia Shilling"
},
{
"symbol": "R",
"code": "ZAR",
"uhex": [
"52"
],
"name": "South Africa Rand"
},
{
"symbol": "\u20a9",
"code": "KRW",
"uhex": [
"20a9"
],
"name": "Korea (South) Won"
},
{
"symbol": "\u20a8",
"code": "LKR",
"uhex": [
"20a8"
],
"name": "Sri Lanka Rupee"
},
{
"symbol": "kr",
"code": "SEK",
"uhex": [
"6b",
"72"
],
"name": "Sweden Krona"
},
{
"symbol": "CHF",
"code": "CHF",
"uhex": [
"43",
"48",
"46"
],
"name": "Switzerland Franc"
},
{
"symbol": "$",
"code": "SRD",
"uhex": [
"24"
],
"name": "Suriname Dollar"
},
{
"symbol": "\u00a3",
"code": "SYP",
"uhex": [
"a3"
],
"name": "Syria Pound"
},
{
"symbol": "NT$",
"code": "TWD",
"uhex": [
"4e",
"54",
"24"
],
"name": "Taiwan New Dollar"
},
{
"symbol": "\u0e3f",
"code": "THB",
"uhex": [
"e3f"
],
"name": "Thailand Baht"
},
{
"symbol": "TT$",
"code": "TTD",
"uhex": [
"54",
"54",
"24"
],
"name": "Trinidad and Tobago Dollar"
},
{
"symbol": "",
"code": "TRY",
"uhex": [],
"name": "Turkey Lira"
},
{
"symbol": "\u20a4",
"code": "TRL",
"uhex": [
"20a4"
],
"name": "Turkey Lira"
},
{
"symbol": "$",
"code": "TVD",
"uhex": [
"24"
],
"name": "Tuvalu Dollar"
},
{
"symbol": "\u20b4",
"code": "UAH",
"uhex": [
"20b4"
],
"name": "Ukraine Hryvna"
},
{
"symbol": "\u00a3",
"code": "GBP",
"uhex": [
"a3"
],
"name": "United Kingdom Pound"
},
{
"symbol": "$",
"code": "USD",
"uhex": [
"24"
],
"name": "United States Dollar"
},
{
"symbol": "$U",
"code": "UYU",
"uhex": [
"24",
"55"
],
"name": "Uruguay Peso"
},
{
"symbol": "\u043b\u0432",
"code": "UZS",
"uhex": [
"43b",
"432"
],
"name": "Uzbekistan Som"
},
{
"symbol": "Bs",
"code": "VEF",
"uhex": [
"42",
"73"
],
"name": "Venezuela Bolivar Fuerte"
},
{
"symbol": "\u20ab",
"code": "VND",
"uhex": [
"20ab"
],
"name": "Viet Nam Dong"
},
{
"symbol": "\ufdfc",
"code": "YER",
"uhex": [
"fdfc"
],
"name": "Yemen Rial"
},
{
"symbol": "Z$",
"code": "ZWD",
"uhex": [
"5a",
"24"
],
"name": "Zimbabwe Dollar"
}
]
def code_symbol_map():
with open(os.path.join(settings.PROJECT_ROOT, 'currencies.json')) as f:
codemaps = simplejson.load(f)
return dict([(c['code'], c['symbol']) for c in codemaps])
LOCALES = ('en_AU.utf8',
'en_BW.utf8',
# ... a finite set of locales
)
def code_symbol_map():
csmap = {}
for loc in LOCALES:
locale.setlocale(locale.LC_ALL, loc)
conv = locale.localeconv()
csmap[conv['int_curr_symbol'].strip()] = conv['currency_symbol']
return csmap
#!/usr/bin/env python
from bs4 import BeautifulSoup
import json
import pprint
pp = pprint.PrettyPrinter(indent=4)
def get_content(file_):
with open(file_) as f:
content = f.read()
return content
def uhex_to_symbol(uhex):
uc = [unichr(int(x, 16)).encode('utf-8') for x in uhex]
return "".join(uc)
def scrape_tr(tr_tag):
row = tr_tag.contents
name = row[0].contents[0]
code = row[1].contents[0]
try:
uhex = [x.strip() for x in row[6].contents[0].split(',')]
except IndexError:
if code.upper() == 'INR':
uhex = ['20b9']
# add more if else conditions here
else:
uhex = []
return {
'name': str(name),
'code': str(code),
'uhex': map(str, uhex),
'symbol': uhex_to_symbol(uhex),
}
def scrape_from_html(file_):
content = get_content(file_)
soup = BeautifulSoup(content)
table_tag = soup.find('table', class_='cSymbl_tbl')
table_body = table_tag.contents[1]
rows = table_body.contents[1:]
codemaps = [scrape_tr(tr) for tr in rows]
return codemaps
def save_as_json(codemaps):
with open('currencies.json', 'w') as f:
f.write(json.dumps(codemaps, indent=4))
def load_from_json(file_):
with open(file_) as f:
codemaps = json.load(f)
return codemaps
def code_symbol_lookup(codemaps):
return dict([(c['code'], c['symbol']) for c in codemaps])
if __name__ == '__main__':
currencies = scrape_from_html('/home/vineet/python/sandbox/currencytable.html')
save_as_json(currencies)
# lookup = code_symbol_lookup(load_from_json('currencies.json'))
# pp.pprint(lookup)

old code

>>> import timeit
>>> t = timeit.Timer("currency.code2symbol('INR')", "from feedapi import currency")
>>> t.repeat(3, 1000000)
[4.077932834625244, 4.061428070068359, 4.066157102584839]

new code

>>> import timeit
>>> t = timeit.Timer("currency.code2symbol('INR')", "from feedapi import currency")
>>> t
<timeit.Timer instance at 0x933314c>
>>> t.repeat(3, 1000000)
[2.2499191761016846, 2.2494049072265625, 2.248082160949707]
>>> t = timeit.Timer("currency.code2symbol('VND')", "from feedapi import currency")
>>> t.repeat(3, 1000000)
[2.304192066192627, 2.3027617931365967, 2.3027539253234863]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment