Skip to content

Commit

Permalink
[#554] Currency Code should be unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Oct 24, 2017
1 parent 2c44d3e commit 477acd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
8 changes: 0 additions & 8 deletions standard/schema/codelists/currency.csv
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ GRD,Drachma,2002-03
GWE,Guinea Escudo,1978 to 1981
GWP,Guinea-Bissau Peso,1997-05
HRD,Croatian Dinar,1995-01
HRK,Croatian Kuna,2015-06
IEP,Irish Pound,2002-03
ILP,Pound,1978 to 1981
ILR,Old Shekel,1989 to 1990
Expand All @@ -251,22 +250,19 @@ MLF,Mali Franc,1984-11
MTL,Maltese Lira,2008-01
MTP,Maltese Pound,1983-06
MVQ,Maldive Rupee,1989-12
MWK,Kwacha,2016-02
MXP,Mexican Peso,1993-01
MZE,Mozambique Escudo,1978 to 1981
MZM,Mozambique Metical,2006-06
NIC,Cordoba,1990-10
NLG,Netherlands Guilder,2002-03
PEH,Sol,1989 to 1990
PEI,Inti,1991-07
PEN,Nuevo Sol ,2015-12
PES,Sol,1986-02
PLZ,Zloty,1997-01
PTE,Portuguese Escudo,2002-03
RHD,Rhodesian Dollar,1978 to 1981
ROK,Leu A/52,1989 to 1990
ROL,Old Leu,2005-06
RON,New Romanian Leu ,2015-06
RUR,Russian Ruble,1993-01
SDD,Sudanese Dinar,2007-07
SDP,Sudanese Pound,1998-06
Expand All @@ -278,16 +274,13 @@ TJR,Tajik Ruble,2001-04
TMM,Turkmenistan Manat,2009-01
TPE,Timor Escudo,2002-11
TRL,Old Turkish Lira,2005-12
TRY,New Turkish Lira,2009-01
UAK,Karbovanet,1996-09
UGS,Uganda Shilling,1987-05
UGW,Old Shilling,1989 to 1990
USS,US Dollar (Same day),2014-03
UYN,Old Uruguay Peso,1989-12
UYP,Uruguayan Peso,1993-03
VEB,Bolivar,2008-01
VEF,Bolivar,2016-02
VEF,Bolivar Fuerte,2011-12
VNC,Old Dong,1989-1990
XEU,European Currency Unit (E.C.U),1999-01
XFO,Gold-Franc,2006-10
Expand All @@ -303,6 +296,5 @@ ZRN,New Zaire,1999-06
ZRZ,Zaire,1994-02
ZWC,Rhodesian Dollar,1989-12
ZWD,Zimbabwe Dollar (old),2006-08
ZWD,Zimbabwe Dollar,2008-08
ZWN,Zimbabwe Dollar (new),2006-09
ZWR,Zimbabwe Dollar,2009-06
18 changes: 8 additions & 10 deletions standard/schema/utils/fetch_currency_codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@
req = requests.get('https://raw.githubusercontent.com/datasets/currency-codes/master/data/codes-all.csv')
lines = req.text.split('\n')
reader = csv.DictReader(lines)
new_data = {}
new_data = OrderedDict()

for row in reader:
if not row['AlphabeticCode']:
continue
unique_fields = (row['AlphabeticCode'], row['Currency'])
if unique_fields not in new_data or row['WithdrawalDate'] < new_data[unique_fields]:
new_data[unique_fields] = row['WithdrawalDate']

new_data = [{
'Code': code,
'Title': title,
'Withdrawal Date': withdrawal,
} for (code, title), withdrawal in new_data.items()]
if (row['AlphabeticCode'] not in new_data
or row['WithdrawalDate'] < new_data[row['AlphabeticCode']]['Withdrawal Date']):
new_data[row['AlphabeticCode']] = {
new_heading: row[old_heading] for new_heading, old_heading in heading_map.items()
}

new_data = list(new_data.values())
new_data.sort(key=lambda row: (row['Withdrawal Date'] != '', row['Code']))

with open('standard/schema/codelists/currency.csv', 'w') as fp:
Expand Down

0 comments on commit 477acd1

Please sign in to comment.