Last active
August 29, 2015 14:21
-
-
Save ejamesc/6d755e6ca2b677aa8862 to your computer and use it in GitHub Desktop.
Currency symbol extractor script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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