Skip to content

Instantly share code, notes, and snippets.

@ejamesc
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save ejamesc/6d755e6ca2b677aa8862 to your computer and use it in GitHub Desktop.

Select an option

Save ejamesc/6d755e6ca2b677aa8862 to your computer and use it in GitHub Desktop.
Currency symbol extractor script
import csv
# data taken from http://www.currency-iso.org/en/home/tables/table-a1.html
# and consolidated.csv from http://datahub.io/dataset/iso-4217-currency-codes/resource/69ec48a5-4195-4439-92cf-d15096b9b20a
current_currencies = set()
with open('active_currencies.txt', 'rb') as file:
for row in file:
r = row.rstrip()
current_currencies.add(r)
all_currencies = {}
with open('consolidated.csv', 'rb') as csvfile:
for row in csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for r in reader:
if r[2] != "":
all_currencies[r[2]] = r[1]
res = set()
for k, v in all_currencies.iteritems():
if k in current_currencies:
r = v + "|" + k
res.add(r)
res_list = list(res)
res_list.sort()
for n in res_list:
print n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment