From c7fc11a4828e6a99080ca1d4667bf6b93bc9fa4c Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Tue, 3 Feb 2015 13:04:09 +0000 Subject: [PATCH 01/28] [#8] Update IANA Media Types import code for CLv3 Also, pull the latest list of codes. --- convert.py | 18 +++ templates/FileFormat.xml | 16 ++- xml/FileFormat.xml | 299 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 308 insertions(+), 25 deletions(-) diff --git a/convert.py b/convert.py index bcf4e8d0..cfdbb9f3 100644 --- a/convert.py +++ b/convert.py @@ -27,5 +27,23 @@ codelist_items.append(codelist_item) +# Adapted from code at http://effbot.org/zone/element-lib.htm +def indent(elem, level=0, shift=2): + i = "\n" + level*" "*shift + if len(elem): + if not elem.text or not elem.text.strip(): + elem.text = i + " "*shift + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for elem in elem: + indent(elem, level+1, shift) + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and (not elem.tail or not elem.tail.strip()): + elem.tail = i + +indent(template.getroot(), 0, 4) + template.write('xml/FileFormat.xml', pretty_print=True) diff --git a/templates/FileFormat.xml b/templates/FileFormat.xml index 8e5a0475..3fd97227 100644 --- a/templates/FileFormat.xml +++ b/templates/FileFormat.xml @@ -1,8 +1,12 @@ - - File Format - File format of published documents. - http://www.iana.org/assignments/media-types - - + + + File Format + + + File format of published documents. + + http://www.iana.org/assignments/media-types + + diff --git a/xml/FileFormat.xml b/xml/FileFormat.xml index 35704e9c..416c61c4 100644 --- a/xml/FileFormat.xml +++ b/xml/FileFormat.xml @@ -13,10 +13,18 @@ application/1d-interleaved-parityfec application + + application/3gpdash-qoe-report+xml + application + application/3gpp-ims+xml application + + application/A2L + application + application/activemessage application @@ -65,6 +73,10 @@ application/alto-networkmap+json application + + application/AML + application + application/andrew-inset application @@ -73,6 +85,14 @@ application/applefile application + + application/ATF + application + + + application/ATFX + application + application/atom+xml application @@ -93,6 +113,10 @@ application/atomsvc+xml application + + application/ATXML + application + application/auth-policy+xml application @@ -137,6 +161,10 @@ application/ccxml+xml application + + application/CDFX+XML + application + application/cdmi-capability application @@ -157,6 +185,10 @@ application/cdmi-queue application + + application/CEA + application + application/cea-2018+xml application @@ -177,6 +209,10 @@ application/cnrp+xml application + + application/coap-group+json + application + application/commonground application @@ -221,6 +257,10 @@ application/dca-rft application + + application/DCD + application + application/dec-dx application @@ -233,6 +273,14 @@ application/dicom application + + application/DII + application + + + application/DIT + application + application/dns application @@ -285,6 +333,10 @@ application/epp+xml application + + application/epub+zip + application + application/eshop application @@ -417,6 +469,14 @@ application/javascript application + + application/jose + application + + + application/jose+json + application + application/jrd+json application @@ -429,6 +489,22 @@ application/json-patch+json application + + application/json-seq + application + + + application/jwk+json + application + + + application/jwk-set+json + application + + + application/jwt + application + application/kpml-request+xml application @@ -457,6 +533,10 @@ application/lostsync+xml application + + application/LXF + application + application/mac-binhex40 application @@ -553,6 +633,10 @@ application/mediaservercontrol+xml application + + application/merge-patch+json + application + application/metalink4+xml application @@ -561,6 +645,10 @@ application/mets+xml application + + application/MF4 + application + application/mikey application @@ -821,6 +909,10 @@ application/raptorfec application + + application/rdap+json + application + application/reginfo+xml application @@ -897,6 +989,10 @@ application/sbml+xml application + + application/scaip+xml + application + application/scvp-cv-request application @@ -978,7 +1074,7 @@ application - application/smil + application/smil - OBSOLETED in favor of application/smil+xml application @@ -1249,6 +1345,18 @@ application/vnd.antix.game-component application + + application/vnd.apache.thrift.binary + application + + + application/vnd.apache.thrift.compact + application + + + application/vnd.apache.thrift.json + application + application/vnd.api+json application @@ -1262,13 +1370,17 @@ application - application/vnd.arastra.swi + application/vnd.arastra.swi - OBSOLETED in favor of application/vnd.aristanetworks.swi application application/vnd.aristanetworks.swi application + + application/vnd.artsquare + application + application/vnd.astraea-software.iota application @@ -1369,6 +1481,10 @@ application/vnd.cluetrust.cartomobile-config-pkg application + + application/vnd.coffeescript + application + application/vnd.collection.doc+json application @@ -1469,6 +1585,10 @@ application/vnd.data-vision.rdz application + + application/vnd.debian.binary-package + application + application/vnd.dece.data application @@ -1517,6 +1637,10 @@ application/vnd.dolby.mobile.2 application + + application/vnd.doremir.scorecloud-binary-document + application + application/vnd.dpgraph application @@ -1621,6 +1745,10 @@ application/vnd.dynageo application + + application/vnd.dzr + application + application/vnd.easykaraoke.cdgdownload application @@ -1661,6 +1789,10 @@ application/vnd.enliven application + + application/vnd.enphase.envoy + application + application/vnd.eprints.data+xml application @@ -1906,7 +2038,11 @@ application - application/vnd.geocube+xml + application/vnd.geo+json + application + + + application/vnd.geocube+xml - OBSOLETED by request application @@ -1942,7 +2078,7 @@ application - application/vnd.gmx + application/vnd.gmx - DEPRECATED application @@ -1953,6 +2089,14 @@ application/vnd.google-earth.kmz application + + application/vnd.gov.sk.e-form+xml + application + + + application/vnd.gov.sk.e-form+zip + application + application/vnd.grafeq application @@ -2097,6 +2241,42 @@ application/vnd.immervision-ivu application + + application/vnd.ims.imsccv1p1 + application + + + application/vnd.ims.imsccv1p2 + application + + + application/vnd.ims.imsccv1p3 + application + + + application/vnd.ims.lis.v2.result+json + application + + + application/vnd.ims.lti.v2.toolconsumerprofile+json + application + + + application/vnd.ims.lti.v2.toolproxy.id+json + application + + + application/vnd.ims.lti.v2.toolproxy+json + application + + + application/vnd.ims.lti.v2.toolsettings+json + application + + + application/vnd.ims.lti.v2.toolsettings.simple+json + application + application/vnd.informedcontrol.rms+xml application @@ -2110,7 +2290,7 @@ application - application/vnd.informix-visionary + application/vnd.informix-visionary - OBSOLETED in favor of application/vnd.visionary application @@ -2365,6 +2545,10 @@ application/vnd.mason+json application + + application/vnd.maxmind.maxmind-db + application + application/vnd.mcd application @@ -2397,6 +2581,10 @@ application/vnd.micrografx.igx application + + application/vnd.miele+json + application + application/vnd.mif application @@ -2494,7 +2682,7 @@ application - application/vnd.mseq + application/vnd.ms-3mfdocument application @@ -2617,6 +2805,14 @@ application/vnd.ms-xpsdocument application + + application/vnd.msa-disk-image + application + + + application/vnd.mseq + application + application/vnd.msign application @@ -2734,7 +2930,7 @@ application - application/vnd.nokia.n-gage.symbian.install + application/vnd.nokia.n-gage.symbian.install - OBSOLETE; no replacement given application @@ -2773,6 +2969,10 @@ application/vnd.ntt-local.file-transfer application + + application/vnd.ntt-local.ogw_remote-access + application + application/vnd.ntt-local.sip-ta_remote application @@ -3361,6 +3561,10 @@ application/vnd.openxmlformats-package.relationships+xml application + + application/vnd.oracle.resource+json + application + application/vnd.orange.indata application @@ -3393,6 +3597,10 @@ application/vnd.palm application + + application/vnd.panoply + application + application/vnd.paos.xml application @@ -3817,6 +4025,10 @@ application/vnd.tcpdump.pcap application + + application/vnd.tmd.mediaflex.api+xml + application + application/vnd.tmobile-livetv application @@ -3913,6 +4125,10 @@ application/vnd.uplanet.signal application + + application/vnd.valve.source.material + application + application/vnd.vcx application @@ -4113,6 +4329,10 @@ application/vnd.yamaha.tunnel-udpencap application + + application/vnd.yaoweme + application + application/vnd.yellowriver-custom-menu application @@ -4165,6 +4385,10 @@ application/wspolicy+xml application + + application/x-www-form-urlencoded + application + application/x400-bp application @@ -4210,7 +4434,7 @@ application - application/xhtml-voice+xml + application/xhtml-voice+xml - OBSOLETE; no replacement given application @@ -4229,6 +4453,10 @@ application/xml-external-parsed-entity application + + application/xml-patch+xml + application + application/xmpp+xml application @@ -4290,7 +4518,11 @@ audio - audio/amr-wb + audio/amr-wb+ + audio + + + audio/aptx audio @@ -4434,11 +4666,11 @@ audio - audio/G722 + audio/G7221 audio - audio/G7221 + audio/G722 audio @@ -4790,7 +5022,7 @@ audio - audio/vnd.qcelp + audio/vnd.qcelp - DEPRECATED in favor of audio/qcelp audio @@ -4989,6 +5221,10 @@ image/vnd.svf image + + image/vnd.tencent.tap + image + image/vnd.valve.source.texture image @@ -5050,7 +5286,7 @@ message - message/news + message/news - OBSOLETED by RFC5537 message @@ -5078,7 +5314,7 @@ message - message/vnd.si.simp + message/vnd.si.simp - OBSOLETED by request message @@ -5129,6 +5365,10 @@ model/vnd.mts model + + model/vnd.opengex + model + model/vnd.parasolid.transmit.binary model @@ -5137,6 +5377,10 @@ model/vnd.parasolid.transmit.text model + + model/vnd.valve.source.compiled-map + model + model/vnd.vtu model @@ -5213,10 +5457,18 @@ multipart/voice-message multipart + + multipart/x-mixed-replace + multipart + text/1d-interleaved-parityfec text + + text/cache-manifest + text + text/calendar text @@ -5230,7 +5482,11 @@ text - text/directory + text/csv-schema + text + + + text/directory - DEPRECATED by RFC6350 text @@ -5238,7 +5494,7 @@ text - text/ecmascript + text/ecmascript - OBSOLETED in favor of application/ecmascript text @@ -5266,13 +5522,17 @@ text - text/javascript + text/javascript - OBSOLETED in favor of application/javascript text text/jcr-cnd text + + text/markdown (TEMPORARY - registered 2014-11-11, expires 2015-11-11) + text + text/mizar text @@ -5446,7 +5706,7 @@ text - text/vnd.si.uricatalogue + text/vnd.si.uricatalogue - OBSOLETED by request text @@ -5562,7 +5822,7 @@ video - video/MJ2 + video/mj2 video @@ -5787,3 +6047,4 @@ + From 6b1db9a285526b692ac481eb06b785e5880e4a55 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Mon, 9 Jun 2014 12:06:49 +0100 Subject: [PATCH 02/28] [#8] Add code to recreate Country codelist from ISO XML --- convert.py | 48 ++++++++++++++++++++++++++++++++++++++++++- templates/Country.xml | 7 +++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 templates/Country.xml diff --git a/convert.py b/convert.py index cfdbb9f3..a75f6498 100644 --- a/convert.py +++ b/convert.py @@ -2,12 +2,18 @@ Converts codelist files from external sources into the format used by IATI. -Currently only supports the IANA Media Types code list (FileFormat). +Note not all external codelists are converted automatically yet. """ from lxml import etree as ET +""" + +IANA Media Types (FileFormat) + +""" + template = ET.parse('templates/FileFormat.xml', ET.XMLParser(remove_blank_text=True)) codelist_items = template.find('codelist-items') @@ -47,3 +53,43 @@ def indent(elem, level=0, shift=2): template.write('xml/FileFormat.xml', pretty_print=True) + + +""" + +ISO Country Alpha 2 + +""" + +XML_LANG = '{http://www.w3.org/XML/1998/namespace}lang' + +template = ET.parse('templates/Country.xml', ET.XMLParser(remove_blank_text=True)) +codelist_items = template.find('codelist-items') + +countries = ET.parse('source/iso_country_codes.xml') +for country in countries.findall('country'): + if country.find('status').text == 'officially-assigned': + codelist_item = ET.Element('codelist-item') + + code = ET.Element('code') + code.text = country.find('alpha-2-code').text + codelist_item.append(code) + + for short_name in country.findall('short-name'): + if XML_LANG in short_name.attrib: + name = ET.Element('name') + name.attrib[XML_LANG] = short_name.attrib[XML_LANG] + name.text = short_name.text + codelist_item.append(name) + + for full_name in country.findall('full-name'): + if XML_LANG in full_name.attrib: + description = ET.Element('description') + description.attrib[XML_LANG] = full_name.attrib[XML_LANG] + description.text = full_name.text + codelist_item.append(description) + + codelist_items.append(codelist_item) + +template.write('xml/Country.xml', pretty_print=True) + diff --git a/templates/Country.xml b/templates/Country.xml new file mode 100644 index 00000000..5e6efe58 --- /dev/null +++ b/templates/Country.xml @@ -0,0 +1,7 @@ + + + Country + http://www.iso.org/iso/home/standards/country_codes.htm + + + From c55181b8b88d5af3d1eb16051360a2c8a0f16719 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Tue, 3 Feb 2015 13:14:20 +0000 Subject: [PATCH 03/28] [#8] Update Country codelist import for CLv3, and redo the import --- convert.py | 54 +- templates/Country.xml | 12 +- xml/Country.xml | 2190 +++++++++++++++++++++++++++++++---------- 3 files changed, 1732 insertions(+), 524 deletions(-) diff --git a/convert.py b/convert.py index a75f6498..b9ec6766 100644 --- a/convert.py +++ b/convert.py @@ -8,6 +8,22 @@ from lxml import etree as ET +# Adapted from code at http://effbot.org/zone/element-lib.htm +def indent(elem, level=0, shift=2): + i = "\n" + level*" "*shift + if len(elem): + if not elem.text or not elem.text.strip(): + elem.text = i + " "*shift + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for elem in elem: + indent(elem, level+1, shift) + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and (not elem.tail or not elem.tail.strip()): + elem.tail = i + """ IANA Media Types (FileFormat) @@ -33,24 +49,7 @@ codelist_items.append(codelist_item) -# Adapted from code at http://effbot.org/zone/element-lib.htm -def indent(elem, level=0, shift=2): - i = "\n" + level*" "*shift - if len(elem): - if not elem.text or not elem.text.strip(): - elem.text = i + " "*shift - if not elem.tail or not elem.tail.strip(): - elem.tail = i - for elem in elem: - indent(elem, level+1, shift) - if not elem.tail or not elem.tail.strip(): - elem.tail = i - else: - if level and (not elem.tail or not elem.tail.strip()): - elem.tail = i - indent(template.getroot(), 0, 4) - template.write('xml/FileFormat.xml', pretty_print=True) @@ -75,21 +74,26 @@ def indent(elem, level=0, shift=2): code.text = country.find('alpha-2-code').text codelist_item.append(code) + name = ET.Element('name') + codelist_item.append(name) for short_name in country.findall('short-name'): if XML_LANG in short_name.attrib: - name = ET.Element('name') - name.attrib[XML_LANG] = short_name.attrib[XML_LANG] - name.text = short_name.text - codelist_item.append(name) + narrative = ET.Element('narrative') + narrative.attrib[XML_LANG] = short_name.attrib[XML_LANG] + narrative.text = short_name.text + name.append(narrative) + description = ET.Element('description') + codelist_item.append(description) for full_name in country.findall('full-name'): if XML_LANG in full_name.attrib: - description = ET.Element('description') - description.attrib[XML_LANG] = full_name.attrib[XML_LANG] - description.text = full_name.text - codelist_item.append(description) + narrative = ET.Element('narrative') + narrative.attrib[XML_LANG] = full_name.attrib[XML_LANG] + narrative.text = full_name.text + description.append(narrative) codelist_items.append(codelist_item) +indent(template.getroot(), 0, 4) template.write('xml/Country.xml', pretty_print=True) diff --git a/templates/Country.xml b/templates/Country.xml index 5e6efe58..9bc7095f 100644 --- a/templates/Country.xml +++ b/templates/Country.xml @@ -1,7 +1,9 @@ - - Country - http://www.iso.org/iso/home/standards/country_codes.htm - - + + + Country + + http://www.iso.org/iso/home/standards/country_codes.htm + + diff --git a/xml/Country.xml b/xml/Country.xml index dc598875..a129e8c3 100644 --- a/xml/Country.xml +++ b/xml/Country.xml @@ -3,1523 +3,2725 @@ Country - - - The Country codelist is generated from the ISO 3166-1 part of the - ISO 3166 standard. The standard makes allowance, alongside the - officially assigned codes, for code elements to be expanded by - using either reserved codes or user-assigned codes. IATI currently - defines additional codes in the XA -XZ range. - - http://www.iso.org/iso/home/standards/country_codes.htm - AF + AD - AFGHANISTAN + Andorra + Andorre (l') + Andorra + + la Principauté d'Andorre + the Principality of Andorra + - AX + AE - Ă…LAND ISLANDS + Al Imārāt + Émirats arabes unis (les) + United Arab Emirates (the) + + les Émirats arabes unis + the United Arab Emirates + - AL + AF - ALBANIA + Afghānestān + Afghānistān + Afghanistan (l') + Afghanistan + + la République islamique d'Afghanistan + the Islamic Republic of Afghanistan + - DZ + AG - ALGERIA + Antigua and Barbuda + Antigua-et-Barbuda + - AS + AI - AMERICAN SAMOA + Anguilla + Anguilla + - AD + AL - ANDORRA + Shqipëria, Shqipëri + Albanie (l') + Albania + + la République d'Albanie + the Republic of Albania + - AO + AM - ANGOLA + Hayastan + Armenia + Arménie (l') + + the Republic of Armenia + la République d'Arménie + - AI + AO - ANGUILLA + Angola + Angola + Angola (l') + + the Republic of Angola + la République d'Angola + AQ - ANTARCTICA - - - - AG - - ANTIGUA AND BARBUDA + Antarctica + Antarctique (l') + AR - ARGENTINA + Argentina (la) + Argentina + Argentine (l') + + the Argentine Republic + la République argentine + - AM + AS - ARMENIA + American Samoa + Samoa américaines (les) + - AW + AT - ARUBA + Österreich + Austria + Autriche (l') + + the Republic of Austria + la République d'Autriche + AU - AUSTRALIA + Australia + Australie (l') + - AT - - AUSTRIA - - - - AZ + AW - AZERBAIJAN + Aruba + Aruba + Aruba + - BS + AX - BAHAMAS + Åland + Åland Islands + Åland(les Îles) + - BH + AZ - BAHRAIN + Azərbaycan + Azerbaijan + Azerbaïdjan (l') + + the Republic of Azerbaijan + la République d'Azerbaïdjan + - BD + BA - BANGLADESH + Bosna i Hercegovina + Bosna i Hercegovina + Bosna i Hercegovina + Bosnia and Herzegovina + Bosnie-Herzégovine (la) + BB - BARBADOS + Barbados + Barbade (la) + - BY + BD - BELARUS + Bangladesh + Bāṁlādesh + Bangladesh (le) + + the People's Republic of Bangladesh + la République populaire du Bangladesh + BE - BELGIUM + Belgium + Belgien + Belgique (la) + België + + the Kingdom of Belgium + le Royaume de Belgique + - BZ + BF - BELIZE + Burkina (le) + Burkina Faso + + le Burkina Faso + - BJ + BG - BENIN + Bulgaria + Bulgaria + Bulgarie (la) + + the Republic of Bulgaria + la République de Bulgarie + - BM + BH - BERMUDA + Bahrain + Al Baḩrayn + Bahreïn + + the Kingdom of Bahrain + le Royaume de Bahreïn + - BT + BI - BHUTAN + Burundi + Burundi (le) + Burundi + + the Republic of Burundi + la République du Burundi + - BO + BJ - BOLIVIA, PLURINATIONAL STATE OF + Benin + Bénin (le) + + the Republic of Benin + la République du Bénin + - BQ + BL - BONAIRE, SAINT EUSTATIUS AND SABA + Saint Barthélemy + Saint-Barthélemy + - BA + BM - BOSNIA AND HERZEGOVINA + Bermuda + Bermudes (les) + - BW + BN - BOTSWANA + Brunei Darussalam + Negara Brunei Darussalam + Brunei (le) + - BV + BO - BOUVET ISLAND + Bolivia, Plurinational State of + Bolivia, Estado Plurinacional de + Bolivie, l'État plurinational de la + + the Plurinational State of Bolivia + l'État plurinational de Bolivie + - BR + BQ - BRAZIL + Bonaire, Sint Eustatius en Saba + Bonaire, Sint Eustatius and Saba + Bonaire, Saint-Eustache et Saba + - IO + BR - BRITISH INDIAN OCEAN TERRITORY + Brazil + Brasil (o) + Brésil (le) + + the Federative Republic of Brazil + la République fédérative du Brésil + - BN + BS - BRUNEI DARUSSALAM + Bahamas (the) + Bahamas (les) + + the Commonwealth of the Bahamas + le Commonwealth des Bahamas + - BG + BT - BULGARIA + Bhutan + Druk-Yul + Bhoutan (le) + + the Kingdom of Bhutan + le Royaume du Bhoutan + - BF + BV - BURKINA FASO + Bouvet Island + Bouvet (l'Île) + Bouvetøya + Bouvetøya + - BI + BW - BURUNDI + Botswana + Botswana (le) + + the Republic of Botswana + la République du Botswana + - KH + BY - CAMBODIA + Belarus + Bielaruś + Belarus' + Bélarus (le) + + the Republic of Belarus + la République du Bélarus + - CM + BZ - CAMEROON + Belize + Belize (le) + CA - CANADA + Canada + Canada (le) + - CV + CC - CAPE VERDE + Cocos (Keeling) Islands (the) + Cocos (les Îles)/ Keeling (les Îles) + - KY + CD - CAYMAN ISLANDS + Congo (the Democratic Republic of the) + Congo (la République démocratique du) + + the Democratic Republic of the Congo + la République démocratique du Congo + CF - CENTRAL AFRICAN REPUBLIC + Central African Republic (the) + République centrafricaine (la) + Ködörösêse tî Bêafrîka + + the Central African Republic + la République centrafricaine + - TD + CG - CHAD + Congo + Congo (le) + + the Republic of the Congo + la République du Congo + - CL + CH - CHILE + Switzerland + Schweiz (die) + Suisse (la) + Svizzera (la) + Svizra (la) + + the Swiss Confederation + la Confédération suisse + - CN + CI - CHINA + Côte d'Ivoire + Côte d'Ivoire (la) + + the Republic of Côte d'Ivoire + la Republic de Côte d'Ivoire + - CX + CK - CHRISTMAS ISLAND + Cook Islands (the) + Cook (les Îles) + - CC + CL - COCOS (KEELING) ISLANDS + Chile + Chili (le) + Chile + + the Republic of Chile + la République du Chili + - CO + CM - COLOMBIA + Cameroon + Cameroun (le) + + the Republic of Cameroon + la République du Cameroun + - KM + CN - COMOROS + China + Chine (la) + Zhongguo + + the People's Republic of China + la République populaire de Chine + - CG + CO - CONGO + Colombia + Colombie (la) + Colombia + + the Republic of Colombia + la République de Colombie + - CD + CR - CONGO, THE DEMOCRATIC REPUBLIC OF THE + Costa Rica + Costa Rica + Costa Rica (le) + + the Republic of Costa Rica + la République du Costa Rica + - CK + CU - COOK ISLANDS + Cuba + Cuba + Cuba + + the Republic of Cuba + la République de Cuba + - CR + CV - COSTA RICA + Cabo Verde + Cabo Verde + Cabo Verde + + the Republic of Cabo Verde + la République du Cabo Verde + - CI + CW - CĂ”TE D'IVOIRE + Curaçao + Curaçao + Curaçao + - HR + CX - CROATIA + Christmas (l'Île) + Christmas Island + - CU + CY - CUBA + Cyprus + Kýpros + Kıbrıs + Chypre + + the Republic of Cyprus + la République de Chypre + - CW + CZ - CURAÇAO + tchèque (la République) + Česko + Czech Republic (the) + + la République tchèque + the Czech Republic + - CY + DE - CYPRUS + Germany + Deutschland + Allemagne (l') + + the Federal Republic of Germany + la République fédérale d'Allemagne + - CZ + DJ - CZECH REPUBLIC + Jībūtī + Djibouti + Djibouti + + the Republic of Djibouti + la République de Djibouti + DK - DENMARK + Denmark + Danmark + Danemark (le) + + the Kingdom of Denmark + le Royaume du Danemark + - DJ + DM - DJIBOUTI + Dominica + Dominique (la) + + the Commonwealth of Dominica + le Commonwealth de Dominique + - DM + DO - DOMINICA + Dominican Republic (the) + República Dominicana (la) + dominicaine (la République) + + the Dominican Republic + la République dominicaine + - DO + DZ - DOMINICAN REPUBLIC + Algeria + Algérie (l') + Al Jazā'ir + + the People's Democratic Republic of Algeria + la République algérienne démocratique et populaire + EC - ECUADOR + Ecuador + Ecuador (el) + Équateur (l') + + the Republic of Ecuador + la République d'Équateur + - EG + EE - EGYPT + Estonia + Eesti + Estonie (l') + + the Republic of Estonia + la République d'Estonie + - SV + EG - EL SALVADOR + Egypt + Mişr + Égypte (l') + + the Arab Republic of Egypt + la République arabe d'Égypte + - GQ + EH - EQUATORIAL GUINEA + Western Sahara* + Sahara occidental (le)* + Aş Şaḩrā' al Gharbīyah + ER - ERITREA + Eritrea + Iertra + Irītrīyā + Érythrée (l') + + the State of Eritrea + l'État d'Érythrée + - EE + ES - ESTONIA + Spain + Espagne (l') + España + + the Kingdom of Spain + le Royaume d'Espagne + ET - ETHIOPIA + Ethiopia + Ītyop'iya + Éthiopie (l') + + the Federal Democratic Republic of Ethiopia + la République fédérale démocratique d'Éthiopie + - FK + FI - FALKLAND ISLANDS (MALVINAS) + Finland + Suomi + Finlande (la) + Finland + + the Republic of Finland + la République de Finlande + - FO + FJ - FAROE ISLANDS + Fiji + Viti + Fidji (les) + + the Republic of Fiji + la République des Fidji + - FJ + FK - FIJI + Falkland Islands (the) [Malvinas] + Falkland (les Îles)/Malouines (les Îles) + - FI + FM - FINLAND + Micronésie, États fédérés de + Micronesia (the Federated States of) + + les États fédérés de Micronésie + the Federated States of Micronesia + - FR + FO - FRANCE + Faroe Islands (the) + Færøerne + Føroyar + Féroé (les Îles) + - GF + FR - FRENCH GUIANA + France (la) + France + + la République française + the French Republic + - PF + GA - FRENCH POLYNESIA + Gabon + Gabon (le) + + the Gabonese Republic + la République gabonaise + - TF + GB - FRENCH SOUTHERN TERRITORIES + Royaume-Uni (le) + United Kingdom (the) + + le Royaume-Uni de Grande-Bretagne et d'Irlande du Nord + the United Kingdom of Great Britain and Northern Ireland + - GA + GD - GABON + Grenada + Grenade (la) + - GM + GE - GAMBIA + Sakartvelo + Georgia + Géorgie (la) + - GE + GF - GEORGIA + Guyane française (la ) + French Guiana + - DE + GG - GERMANY + Guernsey + Guernesey + GH - GHANA + Ghana + Ghana (le) + + the Republic of Ghana + la République du Ghana + GI - GIBRALTAR + Gibraltar + Gibraltar + - GR + GL - GREECE + Greenland + Grønland + Kalaallit Nunaat + Groenland (le) + - GL + GM - GREENLAND + Gambia (The) + Gambie (la) + + the Republic of The Gambia + la République de Gambie + - GD + GN - GRENADA + Guinea + Guinée (la) + + the Republic of Guinea + la République de Guinée + GP - GUADELOUPE + Guadeloupe (la) + Guadeloupe + - GU + GQ - GUAM + Equatorial Guinea + Guinea Ecuatorial + Guinée équatoriale (la) + Guiné Equatorial (a) + + the Republic of Equatorial Guinea + la République de Guinée équatoriale + - GT + GR - GUATEMALA + Greece + Ellás/Elláda + Grèce (la) + + the Hellenic Republic + la République hellénique + - GG + GS - GUERNSEY + Géorgie du Sud-et-les Îles Sandwich du Sud (la) + South Georgia and the South Sandwich Islands + - GN + GT - GUINEA + Guatemala + Guatemala + Guatemala (le) + + the Republic of Guatemala + la République du Guatemala + + + + GU + + Guam + Guam + + GW - GUINEA-BISSAU + Guinea-Bissau + Guiné-Bissau (a) + Guinée-Bissau (la) + + the Republic of Guinea-Bissau + la République de Guinée-Bissau + GY - GUYANA + Guyana + Guyana (le) + + the Republic of Guyana + la République du Guyana + - HT + HK - HAITI + Hong Kong + Xianggang + Hong Kong + + the Hong Kong Special Administrative Region of China + Hong Kong, Région administrative spéciale de Chine (la) + HM - HEARD ISLAND AND MCDONALD ISLANDS + Heard Island and McDonald Islands + Heard-et-Îles MacDonald (l'Île) + + ll'Île Heard-et-Îles MacDonald + - VA + HN - HOLY SEE (VATICAN CITY STATE) + Honduras + Honduras + Honduras (le) + + the Republic of Honduras + la République du Honduras + - HN + HR - HONDURAS + Croatia + Croatie (la) + Hrvatska + + the Republic of Croatia + la République de Croatie + - HK + HT - HONG KONG + Haiti + Haïti + Ayiti + + the Republic of Haiti + la République d'Haïti + HU - HUNGARY + Hungary + Magyarország + Hongrie (la) + - IS + ID - ICELAND + Indonesia + Indonesia + Indonésie (l') + + the Republic of Indonesia + la République d'Indonésie + - IN + IE - INDIA + Ireland + Éire + Irlande (l') + - ID + IL - INDONESIA + Israel + Isrā'īl + Yisra'el + Israël + + the State of Israel + l'État d'Israël + - IR + IM - IRAN, ISLAMIC REPUBLIC OF + Isle of Man + Île de Man + - IQ + IN - IRAQ + Bhārat + Inde (l') + India + + la République de l'Inde + the Republic of India + - IE + IO - IRELAND + Indien (le Territoire britannique de l'océan) + British Indian Ocean Territory (the) + + le Territoire britannique de l'océan Indien + - IM + IQ - ISLE OF MAN + Iraq + Al ‘Irāq + Iraq (l') + + the Republic of Iraq + la République d'Iraq + - IL + IR - ISRAEL + Iran (the Islamic Republic of) + Jomhūrī-ye Eslāmī-ye Īrān + Iran (République Islamique d') + + the Islamic Republic of Iran + la République islamique d'Iran + - IT + IS - ITALY + Iceland + Ísland + Islande (l') + + the Republic of Iceland + la République d'Islande + - JM + IT - JAMAICA + Italy + Italia (l') + Italie (l') + + the Republic of Italy + la République italienne + - JP + JE - JAPAN + Jersey + Jersey + - JE + JM - JERSEY + Jamaica + Jamaïque (la) + JO - JORDAN + Jordan + Al Urdun + Jordanie (la) + + the Hashemite Kingdom of Jordan + le Royaume hachémite de Jordanie + - KZ + JP - KAZAKHSTAN + Japan + Nihon/Nippon + Japon (le) + KE - KENYA + Kenya + Kenya + Kenya (le) + + the Republic of Kenya + la République du Kenya + - KI + KG - KIRIBATI + Kyrgyzstan + Kyrgyzstan + Kyrgyzstan + Kirghizistan (le) + + the Kyrgyz Republic + la République kirghize + - KP + KH - KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF + Cambodia + Cambodge (le) + Kâmpŭchéa + + the Kingdom of Cambodia + le Royaume du Cambodge + - KR + KI - KOREA, REPUBLIC OF + Kiribati + Kiribati (les) + + the Republic of Kiribati + la République de Kiribati + - XK + KM - KOSOVO + Comoros + Al Qamar + Comores (les) + + the Union of the Comoros + l'Union des Comores + - KW + KN - KUWAIT + Saint-Kitts-et-Nevis + Saint Kitts and Nevis + - KG + KP - KYRGYZSTAN + Korea (the Democratic People's Republic of) + Chosŏn + Corée (la République populaire démocratique de ) + + the Democratic People's Republic of Korea + la République populaire démocratique de Corée + - LA + KR - LAO PEOPLE'S DEMOCRATIC REPUBLIC + Korea (the Republic of) + Hanguk + Corée (la République de) + + the Republic of Korea + la République de Corée + - LV + KW - LATVIA + Kuwait + Al Kuwayt + Koweït (le) + + the State of Kuwait + l'État du Koweït + - LB + KY - LEBANON + Cayman Islands (the) + Caïmans (les Îles) + - LS + KZ - LESOTHO + Qazaqstan + Kazahstan + Kazakhstan (le) + Kazakhstan + + la République du Kazakhstan + the Republic of Kazakhstan + - LR + LA - LIBERIA + Lao People's Democratic Republic (the) + Sathalanalat Paxathipatai Paxaxôn Lao + Lao, République démocratique populaire + + the Lao People's Democratic Republic + la République démocratique populaire lao + - LY + LB - LIBYAN ARAB JAMAHIRIYA + Lebanon + Lubnān + Liban (le) + + the Lebanese Republic + la République libanaise + - LI + LC - LIECHTENSTEIN + Sainte-Lucie + Saint Lucia + - LT + LI - LITHUANIA + Liechtenstein + Liechtenstein + Liechtenstein (le) + + the Principality of Liechtenstein + la Principauté du Liechtenstein + - LU + LK - LUXEMBOURG + Sri Lanka + Sri Lanka (le) + Shrī Laṁkā + Ilaṅkai + + the Democratic Socialist Republic of Sri Lanka + la République socialiste démocratique du Sri Lanka + - MO + LR - MACAO + Liberia + Libéria (le) + + the Republic of Liberia + la République du Libéria + - MK + LS - MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF + Lesotho + Lesotho + Lesotho (le) + + the Kingdom of Lesotho + le Royaume du Lesotho + - MG + LT - MADAGASCAR + Lithuania + Lietuva + Lituanie (la) + + the Republic of Lithuania + la République de Lituanie + - MW + LU - MALAWI + Luxembourg + Luxemburg + Lëtzebuerg + Luxembourg (le) + + the Grand Duchy of Luxembourg + le Grand-Duché de Luxembourg + - MY + LV - MALAYSIA + Lettonie (la) + Latvija + Latvia + + la République de Lettonie + the Republic of Latvia + - MV + LY - MALDIVES + Libya + Lībiyā + Libye + - ML + MA - MALI + Morocco + Al Maghrib + Maroc (le) + + the Kingdom of Morocco + le Royaume du Maroc + - MT + MC - MALTA + Monaco + Monaco + + the Principality of Monaco + la Principauté de Monaco + - MH + MD - MARSHALL ISLANDS + Republica Moldova + Moldova , République de + Moldova (the Republic of) + + la République de Moldova + the Republic of Moldova + - MQ + ME - MARTINIQUE + Monténégro (le) + Montenegro + + Monténégro (le) + - MR + MF - MAURITANIA + Saint Martin (French part) + Saint-Martin (partie française) + - MU + MG - MAURITIUS + Madagascar + Madagasikara + Madagascar + + the Republic of Madagascar + la République de Madagascar + - YT + MH - MAYOTTE + Aelōn̄ in M̧ajeļ + Marshall (Îles) + Marshall Islands (the) + + la République des Îles Marshall + the Republic of the Marshall Islands + - MX + MK - MEXICO + Poranešna Jugoslovenska Republika Makedonija + Macedonia (the former Yugoslav Republic of) + Macédoine (l'ex‑République yougoslave de) + + the former Yugoslav Republic of Macedonia + l'ex-République yougoslave de Macédoine + - FM + ML - MICRONESIA, FEDERATED STATES OF + Mali + Mali (le) + + the Republic of Mali + la République du Mali + - MD + MM - MOLDOVA, REPUBLIC OF + Myanma + Myanmar + Myanmar (le) + + the Republic of the Union of Myanmar + la République de l'Union du Myanmar + - MC + MN - MONACO + Mongolia + Mongol + Mongolie (la) + - MN + MO - MONGOLIA + Macau + Aomen + Macao + Macao + + Macao Special Administrative Region of China + Macao, Région administrative spéciale de Chine + - ME + MP - MONTENEGRO + Northern Mariana Islands (the) + Mariannes du Nord (les Îles) + + the Commonwealth of the Northern Mariana Islands + les Îles Mariannes du Nord + - MS + MQ - MONTSERRAT + Martinique (la) + Martinique + - MA + MR - MOROCCO + Mauritania + Mūrītāniyā + Mauritanie (la) + + the Islamic Republic of Mauritania + la République islamique de Mauritanie + - MZ + MS - MOZAMBIQUE + Montserrat + Montserrat + - MM + MT - MYANMAR + Malta + Malta + Malte + + the Republic of Malta + la République de Malte + - NA + MU - NAMIBIA + Maurice + Mauritius + + la République de Maurice + the Republic of Mauritius + - NR + MV - NAURU + Maldives + Dhivehi Raajje + Maldives (les) + + the Republic of Maldives + la République des Maldives + - NP + MW - NEPAL + Malawi + Malaŵi + Malawi (le) + + the Republic of Malawi + la République du Malawi + - NL + MX - NETHERLANDS + Mexico + Mexique (le) + México + + the United Mexican States + les États-Unis du Mexique + - AN + MY - NETHERLAND ANTILLES + Malaysia + Malaysia + Malaisie (la) + - NC + MZ - NEW CALEDONIA + Mozambique + Moçambique + Mozambique (le) + + the Republic of Mozambique + la République du Mozambique + - NZ + NA - NEW ZEALAND + Namibia + Namibie (la) + + the Republic of Namibia + la République de Namibie + - NI + NC - NICARAGUA + New Caledonia + Nouvelle-Calédonie (la) + NE - NIGER + Niger (the) + Niger (le) + + the Republic of the Niger + la République du Niger + - NG + NF - NIGERIA + Norfolk Island + Norfolk (l'Île) + - NU + NG - NIUE + Nigeria + Nigéria (le) + + the Federal Republic of Nigeria + la République fédérale du Nigéria + - NF + NI - NORFOLK ISLAND + Nicaragua + Nicaragua + Nicaragua (le) + + the Republic of Nicaragua + la République du Nicaragua + - MP + NL - NORTHERN MARIANA ISLANDS + Netherlands (the) + Nederland + Pays-Bas (les) + + the Kingdom of the Netherlands + le Royaume des Pays-Bas + NO - NORWAY + Norway + Noreg + Norge + Norvège (la) + + the Kingdom of Norway + le Royaume de Norvège + - OM - - OMAN - - - - PK + NP - PAKISTAN + Nepal + Nepāl + Népal (le) + + the Federal Democratic Republic of Nepal + la République fédérale démocratique du Népal + - PW + NR - PALAU + Nauru + Naoero + Nauru + + the Republic of Nauru + la République de Nauru + - PS + NU - PALESTINIAN TERRITORY, OCCUPIED + Niue + Niue + - PA + NZ - PANAMA + Aotearoa + Nouvelle-Zélande (la) + New Zealand + - PG + OM - PAPUA NEW GUINEA + Oman + ‘Umān + Oman + + the Sultanate of Oman + le Sultanat d'Oman + - PY + PA - PARAGUAY + Panama + Panama (le) + Panamá + + the Republic of Panama + la République du Panama + PE - PERU + Peru + Pérou (le) + Perú + Perú (el) + Perú + + the Republic of Peru + la République du Pérou + - PH + PF - PHILIPPINES + Polynésie française (la) + French Polynesia + - PN + PG - PITCAIRN + Papua New Guinea + Papouasie-Nouvelle-Guinée (la) + Papuaniugini + + the Independent State of Papua New Guinea + l'État indépendant de Papouasie-Nouvelle-Guinée + - PL + PH - POLAND + Philippines (les) + Philippines (the) + Pilipinas + + la République des Philippines + the Republic of the Philippines + - PT + PK - PORTUGAL + Pakistan + Pākistān + Pakistan (le) + + the Islamic Republic of Pakistan + la République islamique du Pakistan + - PR + PL - PUERTO RICO + Poland + Pologne (la) + Polska + + the Republic of Poland + la République de Pologne + - QA + PM - QATAR + Saint Pierre and Miquelon + Saint-Pierre-et-Miquelon + - RE + PN - REUNION + Pitcairn + Pitcairn + - RO + PR - ROMANIA + Porto Rico + Puerto Rico + Puerto Rico + - RU + PS - RUSSIAN FEDERATION + Palestine, State of + Palestine, État de + Dawlat Filasţīn + + the State of Palestine + l'État de Palestine + - RW + PT - RWANDA + Portugal + Portugal (le) + Portugal + + the Portuguese Republic + la République portugaise + - BL + PW - SAINT BARTHÉLEMY + Palau + Palaos (les) + + the Republic of Palau + la République des Palaos + - SH + PY - SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA + Paraguay + Paraguay (le) + Paraguay (el) + Paraguay + + the Republic of Paraguay + la République du Paraguay + - KN + QA - SAINT KITTS AND NEVIS + Qatar + Qatar (le) + Qaţar + + the State of Qatar + l'État du Qatar + - LC + RE - SAINT LUCIA + Réunion (La) + Réunion + - MF + RO - SAINT MARTIN (FRENCH PART) + Roumanie (la) + România + Romania + - PM + RS - SAINT PIERRE AND MIQUELON + Srbija + Serbia + Serbie + + the Republic of Serbia + la République de Serbie + - VC + RU - SAINT VINCENT AND THE GRENADINES + Russian Federation (the) + Russie (la Fédération de) + Rossijskaja Federacija + + the Russian Federation + la Fédération de Russie + - WS + RW - SAMOA + Rwanda + Rwanda (le) + Rwanda + + the Republic of Rwanda + la République du Rwanda + - SM + SA - SAN MARINO + As Su‘ūdīyah + Saudi Arabia + Arabie saoudite (l') + + the Kingdom of Saudi Arabia + le Royaume d'Arabie saoudite + - ST + SB - SAO TOME AND PRINCIPE + Salomon (Îles) + Solomon Islands (the) + + les Îles Salomon + - SA + SC - SAUDI ARABIA + Seychelles (les) + Seychelles + + la République des Seychelles + the Republic of Seychelles + - SN + SD - SENEGAL + Soudan (le) + As Sūdān + Sudan (the) + + la République du Soudan + the Republic of the Sudan + - RS + SE - SERBIA + Suède (la) + Sverige + Sweden + + le Royaume de Suède + the Kingdom of Sweden + - SC + SG - SEYCHELLES + Singapour + Singapore + Singapura + Chiṅkappūr + Xinjiapo + + la République de Singapour + the Republic of Singapore + - SL + SH - SIERRA LEONE + Sainte-Hélène, Ascension et Tristan da Cunha + Saint Helena, Ascension and Tristan da Cunha + - SG + SI - SINGAPORE + Slovénie (la) + Slovenija + Slovenia + + la République de Slovénie + the Republic of Slovenia + - SX + SJ - SINT MAARTEN (DUTCH PART) + Svalbard et l'Île Jan Mayen (le) + Svalbard og Jan Mayen + Svalbard og Jan Mayen + Svalbard and Jan Mayen + SK - SLOVAKIA + Slovakia + Slovaquie (la) + Slovensko + + the Slovak Republic + la République slovaque + - SI + SL - SLOVENIA + Sierra Leone (la) + Sierra Leone + + la République de Sierra Leone + the Republic of Sierra Leone + - SB + SM - SOLOMON ISLANDS + Saint-Marin + San Marino + San Marino + + la République de Saint-Marin + the Republic of San Marino + - SO + SN - SOMALIA + Sénégal (le) + Senegal + + la République du Sénégal + the Republic of Senegal + - ZA + SO - SOUTH AFRICA + Somalie (la) + Aş Şūmāl + Soomaaliya + Somalia + + la République fédérale de Somalie + the Federal Republic of Somalia + - GS + SR - SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS + Suriname (le) + Suriname + Suriname + + la République du Suriname + the Republic of Suriname + SS - SOUTH SUDAN + Soudan du Sud (le) + South Sudan + + la République du Soudan du Sud + the Republic of South Sudan + - ES + ST - SPAIN + Sao Tomé-et-Principe + São Tomé e Príncipe + Sao Tome and Principe + + la République démocratique de Sao Tomé-et-Principe + the Democratic Republic of Sao Tome and Principe + - LK + SV - SRI LANKA + El Salvador + Salvador (le) + El Salvador + + la République d'El Salvador + the Republic of El Salvador + - SD + SX - SUDAN + Sint Maarten + Sint Maarten (Dutch part) + Saint-Martin (partie néerlandaise) + - SR + SY - SURINAME + République arabe syrienne (la) + Al Jumhūrīyah al ‘Arabīyah as Sūrīyah + Syrian Arab Republic (the) + + la République arabe syrienne + the Syrian Arab Republic + - SJ + SZ - SVALBARD AND JAN MAYEN + Swaziland (le) + eSwatini + Swaziland + + le Royaume du Swaziland + the Kingdom of Swaziland + - SZ + TC - SWAZILAND + Turks-et-Caïcos (les Îles) + Turks and Caicos Islands (the) + - SE + TD - SWEDEN + Tshād + Tchad (le) + Chad + + la République du Tchad + the Republic of Chad + - CH + TF - SWITZERLAND + Terres australes françaises (les) + French Southern Territories (the) + - SY + TG - SYRIAN ARAB REPUBLIC + Togo (le) + Togo + + la République togolaise + the Togolese Republic + - TW + TH - TAIWAN, PROVINCE OF CHINA + Thaïlande (la) + Prathet Thai + Thailand + + le Royaume de Thaïlande + the Kingdom of Thailand + TJ - TAJIKISTAN + Tojikiston + Tajikistan + Tadjikistan (le) + + the Republic of Tajikistan + la République du Tadjikistan + - TZ + TK - TANZANIA, UNITED REPUBLIC OF + Tokelau (les) + Tokelau + - TH + TL - THAILAND + Timor-Leste (le) + Timor-Leste + Timor-Leste + + la République démocratique du Timor-Leste + the Democratic Republic of Timor-Leste + - TL + TM - TIMOR-LESTE + Türkmenistan + Turkmenistan + Turkménistan (le) + - TG + TN - TOGO + Tunisie (la) + Tūnus + Tunisia + + la République tunisienne + the Republic of Tunisia + - TK + TO - TOKELAU + Tonga (les) + Tonga + Tonga + + le Royaume des Tonga + the Kingdom of Tonga + - TO + TR - TONGA + Türkiye + Turquie (la) + Turkey + + la République turque + the Republic of Turkey + TT - TRINIDAD AND TOBAGO + Trinité-et-Tobago (la) + Trinidad and Tobago + + la République de Trinité-et-Tobago + the Republic of Trinidad and Tobago + - TN + TV - TUNISIA + Tuvalu + Tuvalu (les) + - TR + TW - TURKEY + Taïwan (Province de Chine) + Taiwan + Taiwan (Province of China) + - TM + TZ - TURKMENISTAN + Tanzanie, République-Unie de + Jamhuri ya Muungano wa Tanzania + Tanzania, United Republic of + + la République-Unie de Tanzanie + the United Republic of Tanzania + - TC + UA - TURKS AND CAICOS ISLANDS + Ukraine (l') + Ukraina + Ukraine + - TV + UG - TUVALU + Ouganda (l') + Uganda + + la République d'Ouganda + the Republic of Uganda + - UG + UM - UGANDA + Îles mineures éloignées des États-Unis (les) + United States Minor Outlying Islands (the) + - UA + US - UKRAINE + États-Unis (les) + United States (the) + + les États-Unis d'Amérique + the United States of America + - AE + UY - UNITED ARAB EMIRATES + Uruguay (l') + Uruguay (el) + Uruguay + + la République orientale de l'Uruguay + the Eastern Republic of Uruguay + - GB + UZ - UNITED KINGDOM + O‘zbekiston + Uzbekistan + Ouzbékistan (l') + + the Republic of Uzbekistan + la République d'Ouzbékistan + - US + VA - UNITED STATES + Santa Sede (la) + Sancta Sedes + Saint-Siège (le) [État de la Cité du Vatican (l')] + Holy See (the) [Vatican City State] + - UM + VC - UNITED STATES MINOR OUTLYING ISLANDS + Saint-Vincent-et-les-Grenadines + Saint Vincent and the Grenadines + - UY + VE - URUGUAY + Venezuela, République bolivarienne du  + Venezuela, República Bolivariana de + Venezuela, Bolivarian Republic of  + + la République bolivarienne du Venezuela + the Bolivarian Republic of Venezuela + - UZ + VG - UZBEKISTAN + Vierges britanniques (les Îles) + Virgin Islands (British) + + British Virgin Islands (the) + - VU + VI - VANUATU + Vierges des États-Unis (les Îles) + Virgin Islands (U.S.) + + the Virgin Islands of the United States + - VE + VN - VENEZUELA, BOLIVARIAN REPUBLIC OF + Việt Nam + Viet Nam + Viet Nam (le) + + the Socialist Republic of Viet Nam + la République socialiste du Viet Nam + - VN + VU - VIET NAM + Vanuatu + Vanuatu + Vanuatu (le) + + the Republic of Vanuatu + la République du Vanuatu + - VG + WF - VIRGIN ISLANDS, BRITISH + Wallis and Futuna + Wallis-et-Futuna + + Wallis and Futuna Islands + les Îles Wallis-et-Futuna + - VI + WS - VIRGIN ISLANDS, U.S. + Samoa (les) + Samoa + Samoa + + l'État indépendant du Samoa + the Independent State of Samoa + - WF + YE - WALLIS AND FUTUNA + Yémen (le) + Al Yaman + Yemen + + la République du Yémen + the Republic of Yemen + - EH + YT - WESTERN SAHARA + Mayotte + Mayotte + - YE + ZA - YEMEN + Afrique du Sud (l') + Suid-Afrika + South Africa + Sewula Afrika + Afrika-Borwa + Ningizimu Afrika + Afrika-Dzonga + Afrika-Borwa + Afrika Tshipembe + Mzantsi Afrika + Ningizimu Afrika + + la République sud-africaine + the Republic of South Africa + ZM - ZAMBIA + Zambie (la) + Zambia + + la République de Zambie + the Republic of Zambia + ZW - ZIMBABWE + Zimbabwe (le) + Zimbabwe + + la République du Zimbabwe + the Republic of Zimbabwe + + From e38c5721bfb09e57339a1d5b4f52f9831c096a48 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Mon, 9 Jun 2014 12:19:18 +0100 Subject: [PATCH 04/28] [#8] Add code to recreate currency codelist from ISO XML --- convert.py | 38 ++++++++++++++++++++++++++++++++++++++ get.sh | 2 ++ templates/Currency.xml | 8 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 templates/Currency.xml diff --git a/convert.py b/convert.py index b9ec6766..f9800b54 100644 --- a/convert.py +++ b/convert.py @@ -97,3 +97,41 @@ def indent(elem, level=0, shift=2): indent(template.getroot(), 0, 4) template.write('xml/Country.xml', pretty_print=True) + + +""" + +ISO Currency Alpha Code + +""" + +template = ET.parse('templates/Currency.xml', ET.XMLParser(remove_blank_text=True)) +codelist_items = template.find('codelist-items') + +currency_codes = {} +country_currencies = ET.parse('source/table_a1.xml') +for country_currency in country_currencies.find('CcyTbl').findall('CcyNtry'): + currency_name = country_currency.find('CcyNm').text + if currency_name == 'No universal currency': + continue + currency_code = country_currency.find('Ccy').text + if currency_code in currency_codes: + assert currency_codes[currency_code] == currency_name + else: + currency_codes[currency_code] = currency_name + +for currency_code, currency_name in sorted(currency_codes.items()): + codelist_item = ET.Element('codelist-item') + + code = ET.Element('code') + code.text = currency_code + codelist_item.append(code) + + name = ET.Element('name') + name.text = currency_name + codelist_item.append(name) + + codelist_items.append(codelist_item) + +template.write('xml/Currency.xml', pretty_print=True) + diff --git a/get.sh b/get.sh index 627026d2..ec5b8d20 100755 --- a/get.sh +++ b/get.sh @@ -1 +1,3 @@ +mkdir source wget "https://www.iana.org/assignments/media-types/media-types.xml" -O source/media-types.xml +wget "http://www.currency-iso.org/dam/downloads/table_a1.xml" -O source/table_a1.xml diff --git a/templates/Currency.xml b/templates/Currency.xml new file mode 100644 index 00000000..63fd842f --- /dev/null +++ b/templates/Currency.xml @@ -0,0 +1,8 @@ + + + Currency + ISO 4217 Currency used for all transactions and budgets + http://www.iso.org/iso/home/standards/currency_codes.htm + + + From c9a2723af9973a0e64b6848a67be80f7a80952de Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Tue, 3 Feb 2015 13:22:44 +0000 Subject: [PATCH 05/28] [#8] Update Currency codelist import for CLv3, and redo the import --- convert.py | 5 +- templates/Currency.xml | 18 ++++-- xml/Currency.xml | 143 +++++++++++++++++++++++++++++++---------- 3 files changed, 123 insertions(+), 43 deletions(-) diff --git a/convert.py b/convert.py index f9800b54..ddbdc240 100644 --- a/convert.py +++ b/convert.py @@ -128,10 +128,13 @@ def indent(elem, level=0, shift=2): codelist_item.append(code) name = ET.Element('name') - name.text = currency_name codelist_item.append(name) + narrative = ET.Element('narrative') + narrative.text = currency_name + name.append(narrative) codelist_items.append(codelist_item) +indent(template.getroot(), 0, 4) template.write('xml/Currency.xml', pretty_print=True) diff --git a/templates/Currency.xml b/templates/Currency.xml index 63fd842f..ccae0bad 100644 --- a/templates/Currency.xml +++ b/templates/Currency.xml @@ -1,8 +1,12 @@ - - - Currency - ISO 4217 Currency used for all transactions and budgets - http://www.iso.org/iso/home/standards/currency_codes.htm - - + + + + >Currency + + + ISO 4217 Currency used for all transactions and budgets + + http://www.iso.org/iso/home/standards/currency_codes.htm + + diff --git a/xml/Currency.xml b/xml/Currency.xml index 2ff038d1..f13e7ef3 100644 --- a/xml/Currency.xml +++ b/xml/Currency.xml @@ -1,7 +1,7 @@ - Currency + >Currency ISO 4217 Currency used for all transactions and budgets @@ -36,7 +36,7 @@ ANG - Netherlands Antillian Guilder + Netherlands Antillean Guilder @@ -60,7 +60,7 @@ AWG - Aruban Guilder + Aruban Florin @@ -72,7 +72,7 @@ BAM - Convertible Marks + Convertible Mark @@ -177,16 +177,28 @@ Congolese Franc + + CHE + + WIR Euro + + CHF Swiss Franc + + CHW + + WIR Franc + + CLF - Unidades de fomento + Unidad de Fomento @@ -267,12 +279,6 @@ Algerian Dinar - - EEK - - Kroon - - EGP @@ -324,7 +330,7 @@ GHS - Cedi + Ghana Cedi @@ -531,12 +537,6 @@ Lithuanian Litas - - LVL - - Latvian Lats - - LYD @@ -606,7 +606,7 @@ MWK - Malawi Kwacha + Kwacha @@ -630,7 +630,7 @@ MZN - Metical + Mozambique Metical @@ -726,7 +726,7 @@ RON - New Leu + New Romanian Leu @@ -802,15 +802,15 @@ - SSP + SRD - South Sudanese Pound + Surinam Dollar - SRD + SSP - Surinam Dollar + South Sudanese Pound @@ -852,7 +852,7 @@ TMT - Manat + Turkmenistan New Manat @@ -864,7 +864,7 @@ TOP - Paanga + Pa’anga @@ -915,16 +915,10 @@ US Dollar (Next day) - - USS - - US Dollar (Same day) - - UYI - Uruguay Peso en Unidades Indexadas + Uruguay Peso en Unidades Indexadas (URUIURUI) @@ -969,24 +963,102 @@ CFA Franc BEAC + + XAG + + Silver + + + + XAU + + Gold + + + + XBA + + Bond Markets Unit European Composite Unit (EURCO) + + + + XBB + + Bond Markets Unit European Monetary Unit (E.M.U.-6) + + + + XBC + + Bond Markets Unit European Unit of Account 9 (E.U.A.-9) + + + + XBD + + Bond Markets Unit European Unit of Account 17 (E.U.A.-17) + + XCD East Caribbean Dollar + + XDR + + SDR (Special Drawing Right) + + XOF CFA Franc BCEAO + + XPD + + Palladium + + XPF CFP Franc + + XPT + + Platinum + + + + XSU + + Sucre + + + + XTS + + Codes specifically reserved for testing purposes + + + + XUA + + ADB Unit of Account + + + + XXX + + The codes assigned for transactions where no currency is involved + + YER @@ -1000,7 +1072,7 @@ - ZMK + ZMW Zambian Kwacha @@ -1013,3 +1085,4 @@ + From 70c3f090627540e2a512ee27d3e7dd3f7e2dbfec Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Tue, 3 Feb 2015 14:48:29 +0000 Subject: [PATCH 06/28] [#8] Add Kosovo to Country template to ensure it stays in the IATI XML --- templates/Country.xml | 9 ++++++++- xml/Country.xml | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/Country.xml b/templates/Country.xml index 9bc7095f..32ccbefc 100644 --- a/templates/Country.xml +++ b/templates/Country.xml @@ -5,5 +5,12 @@ http://www.iso.org/iso/home/standards/country_codes.htm - + + + XK + + Kosovo + + + diff --git a/xml/Country.xml b/xml/Country.xml index a129e8c3..59c1cb4e 100644 --- a/xml/Country.xml +++ b/xml/Country.xml @@ -6,6 +6,12 @@ http://www.iso.org/iso/home/standards/country_codes.htm + + XK + + Kosovo + + AD From f685b0fe115cba3e0e596e75341b42773eac9dc6 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 4 Feb 2015 10:02:41 +0000 Subject: [PATCH 07/28] [#9] Import historic codes to Currency codelist --- .travis.yml | 2 +- convert.py | 59 ++-- get.sh | 1 + xml/Currency.xml | 740 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 770 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5fa7eeff..4161855f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -qq libxml2-utils script: - - wget "https://raw.githubusercontent.com/IATI/IATI-Codelists/version-2.01/codelist.xsd"; wget "https://raw.githubusercontent.com/IATI/IATI-Codelists/version-2.01/xml.xsd"; xmllint --schema codelist.xsd --noout xml/* + - wget "https://raw.githubusercontent.com/IATI/IATI-Codelists/historic-codes/codelist.xsd"; wget "https://raw.githubusercontent.com/IATI/IATI-Codelists/historic-codes/xml.xsd"; xmllint --schema codelist.xsd --noout xml/* diff --git a/convert.py b/convert.py index ddbdc240..b89180c0 100644 --- a/convert.py +++ b/convert.py @@ -109,31 +109,42 @@ def indent(elem, level=0, shift=2): codelist_items = template.find('codelist-items') currency_codes = {} -country_currencies = ET.parse('source/table_a1.xml') -for country_currency in country_currencies.find('CcyTbl').findall('CcyNtry'): - currency_name = country_currency.find('CcyNm').text - if currency_name == 'No universal currency': - continue - currency_code = country_currency.find('Ccy').text - if currency_code in currency_codes: - assert currency_codes[currency_code] == currency_name +for source_filename, historic in [ ('source/table_a1.xml', False), ('source/table_a3.xml', True) ]: + country_currency_xml = ET.parse(source_filename) + if historic: + country_currencies = country_currency_xml.find('HstrcCcyTbl').findall('HstrcCcyNtry') else: - currency_codes[currency_code] = currency_name - -for currency_code, currency_name in sorted(currency_codes.items()): - codelist_item = ET.Element('codelist-item') - - code = ET.Element('code') - code.text = currency_code - codelist_item.append(code) - - name = ET.Element('name') - codelist_item.append(name) - narrative = ET.Element('narrative') - narrative.text = currency_name - name.append(narrative) - - codelist_items.append(codelist_item) + country_currencies = country_currency_xml.find('CcyTbl').findall('CcyNtry') + for country_currency in country_currencies: + currency_name = country_currency.find('CcyNm').text + if currency_name == 'No universal currency': + continue + currency_code = country_currency.find('Ccy').text + if currency_code in currency_codes: + if not currency_codes[currency_code][0] == currency_name: + print 'Duplicate found for code {}, using name "{}" instead of name "{}" because it occurs first'.format(currency_code, currency_codes[currency_code], currency_name) + else: + currency_codes[currency_code] = (currency_name, country_currency.find('WthdrwlDt').text if historic else None) + +for histroic_section in [False, True]: + for currency_code, (currency_name, withdrawal_date) in sorted(currency_codes.items()): + if (withdrawal_date is None) == histroic_section: + continue + codelist_item = ET.Element('codelist-item') + if withdrawal_date: + codelist_item.attrib['withdrawn'] = withdrawal_date + + code = ET.Element('code') + code.text = currency_code + codelist_item.append(code) + + name = ET.Element('name') + codelist_item.append(name) + narrative = ET.Element('narrative') + narrative.text = currency_name + name.append(narrative) + + codelist_items.append(codelist_item) indent(template.getroot(), 0, 4) template.write('xml/Currency.xml', pretty_print=True) diff --git a/get.sh b/get.sh index ec5b8d20..45669ca7 100755 --- a/get.sh +++ b/get.sh @@ -1,3 +1,4 @@ mkdir source wget "https://www.iana.org/assignments/media-types/media-types.xml" -O source/media-types.xml wget "http://www.currency-iso.org/dam/downloads/table_a1.xml" -O source/table_a1.xml +wget "http://www.currency-iso.org/dam/downloads/table_a3.xml" -O source/table_a3.xml diff --git a/xml/Currency.xml b/xml/Currency.xml index f13e7ef3..26af7a43 100644 --- a/xml/Currency.xml +++ b/xml/Currency.xml @@ -246,7 +246,7 @@ CVE - Cape Verde Escudo + Cabo Verde Escudo @@ -531,12 +531,6 @@ Loti - - LTL - - Lithuanian Litas - - LYD @@ -1083,6 +1077,738 @@ Zimbabwe Dollar + + ADP + + Andorran Peseta + + + + AFA + + Afghani + + + + ALK + + Old Lek + + + + AOK + + Kwanza + + + + AON + + New Kwanza + + + + AOR + + Kwanza Reajustado + + + + ARA + + Austral + + + + ARP + + Peso Argentino + + + + ARY + + Peso + + + + ATS + + Schilling + + + + AYM + + Azerbaijan Manat + + + + AZM + + Azerbaijanian Manat + + + + BAD + + Dinar + + + + BEC + + Convertible Franc + + + + BEF + + Belgian Franc + + + + BEL + + Financial Franc + + + + BGJ + + Lev A/52 + + + + BGK + + Lev A/62 + + + + BGL + + Lev + + + + BOP + + Peso boliviano + + + + BRB + + Cruzeiro + + + + BRC + + Cruzado + + + + BRE + + Cruzeiro + + + + BRN + + New Cruzado + + + + BRR + + Cruzeiro Real + + + + BUK + + N.A. + + + + BYB + + Belarussian Ruble + + + + CHC + + WIR Franc (for electronic) + + + + CNX + + Peoples Bank Dollar + + + + CSD + + Serbian Dinar + + + + CSJ + + Krona A/53 + + + + CSK + + Koruna + + + + CYP + + Cyprus Pound + + + + DDM + + Mark der DDR + + + + DEM + + Deutsche Mark + + + + ECS + + Sucre + + + + ECV + + Unidad de Valor Constante (UVC) + + + + EEK + + Kroon + + + + EQE + + Ekwele + + + + ESA + + Spanish Peseta + + + + ESB + + "A" Account (convertible Peseta Account) + + + + ESP + + Spanish Peseta + + + + FIM + + Markka + + + + FRF + + French Franc + + + + GEK + + Georgian Coupon + + + + GHC + + Cedi + + + + GHP + + Ghana Cedi + + + + GNE + + Syli + + + + GNS + + Syli + + + + GQE + + Ekwele + + + + GRD + + Drachma + + + + GWE + + Guinea Escudo + + + + GWP + + Guinea-Bissau Peso + + + + HRD + + Croatian Dinar + + + + IEP + + Irish Pound + + + + ILP + + Pound + + + + ILR + + Old Shekel + + + + ISJ + + Old Krona + + + + ITL + + Italian Lira + + + + LAJ + + Kip Pot Pol + + + + LSM + + Maloti + + + + LTL + + Lithuanian Litas + + + + LTT + + Talonas + + + + LUC + + Luxembourg Convertible Franc + + + + LUF + + Luxembourg Franc + + + + LUL + + Luxembourg Financial Franc + + + + LVL + + Latvian Lats + + + + LVR + + Latvian Ruble + + + + MAF + + Mali Franc + + + + MGF + + Malagasy Franc + + + + MLF + + Mali Franc + + + + MTL + + Maltese Lira + + + + MTP + + Maltese Pound + + + + MVQ + + Maldive Rupee + + + + MXP + + Mexican Peso + + + + MZE + + Mozambique Escudo + + + + MZM + + Mozambique Metical + + + + NIC + + Cordoba + + + + NLG + + Netherlands Guilder + + + + PEH + + Sol + + + + PEI + + Inti + + + + PES + + Sol + + + + PLZ + + Zloty + + + + PTE + + Portuguese Escudo + + + + RHD + + Rhodesian Dollar + + + + ROK + + Leu A/52 + + + + ROL + + Old Leu + + + + RUR + + Russian Ruble + + + + SDD + + Sudanese Dinar + + + + SDP + + Sudanese Pound + + + + SIT + + Tolar + + + + SKK + + Slovak Koruna + + + + SRG + + Surinam Guilder + + + + SUR + + Rouble + + + + TJR + + Tajik Ruble + + + + TMM + + Turkmenistan Manat + + + + TPE + + Timor Escudo + + + + TRL + + Old Turkish Lira + + + + UAK + + Karbovanet + + + + UGS + + Uganda Shilling + + + + UGW + + Old Shilling + + + + USS + + US Dollar (Same day) + + + + UYN + + Old Uruguay Peso + + + + UYP + + Uruguayan Peso + + + + VEB + + Bolivar + + + + VNC + + Old Dong + + + + XEU + + European Currency Unit (E.C.U) + + + + XFO + + Gold-Franc + + + + XFU + + UIC-Franc + + + + XRE + + RINET Funds Code + + + + YDD + + Yemeni Dinar + + + + YUD + + New Yugoslavian Dinar + + + + YUM + + New Dinar + + + + YUN + + Yugoslavian Dinar + + + + ZAL + + Financial Rand + + + + ZMK + + Zambian Kwacha + + + + ZRN + + New Zaire + + + + ZRZ + + Zaire + + + + ZWC + + Rhodesian Dollar + + + + ZWD + + Zimbabwe Dollar (old) + + + + ZWN + + Zimbabwe Dollar (new) + + + + ZWR + + Zimbabwe Dollar + + From feaf574791bca0f238f23206e5e9633e56765753 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 4 Feb 2015 15:54:42 +0000 Subject: [PATCH 08/28] [#9] Import historic codes to Country codelist --- convert.py | 61 +++++---- xml/Country.xml | 352 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 389 insertions(+), 24 deletions(-) diff --git a/convert.py b/convert.py index b89180c0..555c5285 100644 --- a/convert.py +++ b/convert.py @@ -65,34 +65,46 @@ def indent(elem, level=0, shift=2): template = ET.parse('templates/Country.xml', ET.XMLParser(remove_blank_text=True)) codelist_items = template.find('codelist-items') +def add_code(code_text, country, withdrawn): + codelist_item = ET.Element('codelist-item') + + if withdrawn: + codelist_item.attrib['withdrawn'] = withdrawn + + code = ET.Element('code') + code.text = code_text + codelist_item.append(code) + + name = ET.Element('name') + codelist_item.append(name) + for short_name in country.findall('short-name'): + if XML_LANG in short_name.attrib: + narrative = ET.Element('narrative') + narrative.attrib[XML_LANG] = short_name.attrib[XML_LANG] + narrative.text = short_name.text + name.append(narrative) + + description = ET.Element('description') + codelist_item.append(description) + for full_name in country.findall('full-name'): + if XML_LANG in full_name.attrib: + narrative = ET.Element('narrative') + narrative.attrib[XML_LANG] = full_name.attrib[XML_LANG] + narrative.text = full_name.text + description.append(narrative) + + codelist_items.append(codelist_item) + countries = ET.parse('source/iso_country_codes.xml') for country in countries.findall('country'): if country.find('status').text == 'officially-assigned': - codelist_item = ET.Element('codelist-item') - - code = ET.Element('code') - code.text = country.find('alpha-2-code').text - codelist_item.append(code) - - name = ET.Element('name') - codelist_item.append(name) - for short_name in country.findall('short-name'): - if XML_LANG in short_name.attrib: - narrative = ET.Element('narrative') - narrative.attrib[XML_LANG] = short_name.attrib[XML_LANG] - narrative.text = short_name.text - name.append(narrative) - - description = ET.Element('description') - codelist_item.append(description) - for full_name in country.findall('full-name'): - if XML_LANG in full_name.attrib: - narrative = ET.Element('narrative') - narrative.attrib[XML_LANG] = full_name.attrib[XML_LANG] - narrative.text = full_name.text - description.append(narrative) + add_code(country.find('alpha-2-code').text, country, None) - codelist_items.append(codelist_item) +# Ensure that historic codes come after current codes +for country in countries.findall('country'): + if country.find('status').text == 'formerly-used': + add_code(country.find('alpha-2-code').text, country, country.find('validity-end-date').text) + add_code(country.find('alpha-4-code').text, country, country.find('validity-end-date').text) indent(template.getroot(), 0, 4) template.write('xml/Country.xml', pretty_print=True) @@ -126,6 +138,7 @@ def indent(elem, level=0, shift=2): else: currency_codes[currency_code] = (currency_name, country_currency.find('WthdrwlDt').text if historic else None) +# Ensure that historic codes come after current codes for histroic_section in [False, True]: for currency_code, (currency_name, withdrawal_date) in sorted(currency_codes.items()): if (withdrawal_date is None) == histroic_section: diff --git a/xml/Country.xml b/xml/Country.xml index 59c1cb4e..d0492fc2 100644 --- a/xml/Country.xml +++ b/xml/Country.xml @@ -2728,6 +2728,358 @@ the Republic of Zimbabwe + + AI + + French Afars and Issas + Afars et Issas + + + + + AIDJ + + French Afars and Issas + Afars et Issas + + + + + BQ + + British Antarctic Territory + Antarctique, Territoire britannique de l' + + + + + BQAQ + + British Antarctic Territory + Antarctique, Territoire britannique de l' + + + + + BY + + Byelorussian SSR + Biélorussie, RSS de + + + + + BYAA + + Byelorussian SSR + Biélorussie, RSS de + + + + + CS + + Czechoslovakia + Tchécoslovaquie + + + + + CSHH + + Czechoslovakia + Tchécoslovaquie + + + + + CT + + Canton and Enderbury Islands + Canton et Enderbury, Îles + + + + + CTKI + + Canton and Enderbury Islands + Canton et Enderbury, Îles + + + + + DD + + German Democratic Republic + Allemande, République démocratique + + + + + DDDE + + German Democratic Republic + Allemande, République démocratique + + + + + DY + + Dahomey + Dahomey + + + + + DYBJ + + Dahomey + Dahomey + + + + + FQ + + French Southern and Antarctic Territories + Australes et Antarctiques françaises, Terres + + + + + FQHH + + French Southern and Antarctic Territories + Australes et Antarctiques françaises, Terres + + + + + GE + + Gilbert et Ellice, Îles + Gilbert and Ellice Islands + + + + + GEHH + + Gilbert et Ellice, Îles + Gilbert and Ellice Islands + + + + + HV + + Upper Volta + Haute-Volta + + + + + HVBF + + Upper Volta + Haute-Volta + + + + + JT + + Johnston Island + Johnston, Île + + + + + JTUM + + Johnston Island + Johnston, Île + + + + + MI + + Midway Islands + Midway, Îles + + + + + MIUM + + Midway Islands + Midway, Îles + + + + + NH + + New Hebrides + Nouvelles-Hébrides + + + + + NHVU + + New Hebrides + Nouvelles-Hébrides + + + + + NQ + + Dronning Maud Land + Terre de la Reine Maud + + + + + NQAQ + + Dronning Maud Land + Terre de la Reine Maud + + + + + PC + + Pacific Islands (Trust Territory) + Pacifique, Îles du (territoire sous tutelle) + + + + + PCHH + + Pacific Islands (Trust Territory) + Pacifique, Îles du (territoire sous tutelle) + + + + + PU + + United States Miscellaneous Pacific Islands + Pacifique, Diverses îles du (États-Unis) + + + + + PUUM + + United States Miscellaneous Pacific Islands + Pacifique, Diverses îles du (États-Unis) + + + + + PZ + + Panama Canal Zone + Panama, Zone du Canal de + + + + + PZPA + + Panama Canal Zone + Panama, Zone du Canal de + + + + + RH + + Southern Rhodesia + Rhodésie du Sud + + + + + RHZW + + Southern Rhodesia + Rhodésie du Sud + + + + + SK + + Sikkim + Sikkim + + + + + SKIN + + Sikkim + Sikkim + + + + + VD + + Viet-Nam, Democratic Republic of + Viet-Nam, République démocratique du + + + + + VDVN + + Viet-Nam, Democratic Republic of + Viet-Nam, République démocratique du + + + + + WK + + Wake, Île de + Wake Island + + + + + WKUM + + Wake, Île de + Wake Island + + + + + YD + + Yémen démocratique + Yemen, Democratic + + + + + YDYE + + Yémen démocratique + Yemen, Democratic + + + From ef5404d8726aedd0b1ad2b923a16d7c71f5a74a6 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 4 Feb 2015 17:04:03 +0000 Subject: [PATCH 09/28] [#9] Add transationally-reserved codes to Country list --- convert.py | 2 +- xml/Country.xml | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/convert.py b/convert.py index 555c5285..3616fe5e 100644 --- a/convert.py +++ b/convert.py @@ -102,7 +102,7 @@ def add_code(code_text, country, withdrawn): # Ensure that historic codes come after current codes for country in countries.findall('country'): - if country.find('status').text == 'formerly-used': + if country.find('status').text in ['formerly-used', 'transitionally-reserved']: add_code(country.find('alpha-2-code').text, country, country.find('validity-end-date').text) add_code(country.find('alpha-4-code').text, country, country.find('validity-end-date').text) diff --git a/xml/Country.xml b/xml/Country.xml index d0492fc2..f68cdc78 100644 --- a/xml/Country.xml +++ b/xml/Country.xml @@ -2744,6 +2744,22 @@ + + AN + + Antilles néerlandaises (les ) + Netherlands Antilles + + + + + ANHH + + Antilles néerlandaises (les ) + Netherlands Antilles + + + BQ @@ -2760,6 +2776,22 @@ + + BU + + Burma + Birmanie + + + + + BUMM + + Burma + Birmanie + + + BY @@ -2776,6 +2808,22 @@ + + CS + + Serbia and Montenegro + Serbie-et-Monténégro + + + + + CSXX + + Serbia and Montenegro + Serbie-et-Monténégro + + + CS @@ -2952,6 +3000,22 @@ + + NT + + Neutral Zone + Zone neutre + + + + + NTHH + + Neutral Zone + Zone neutre + + + PC @@ -3032,6 +3096,22 @@ + + TP + + East Timor + Timor oriental + + + + + TPTL + + East Timor + Timor oriental + + + VD @@ -3080,6 +3160,38 @@ + + YU + + Yougoslavie + Yugoslavia + + + + + YUCS + + Yougoslavie + Yugoslavia + + + + + ZR + + Zaire + Zaïre + + + + + ZRCD + + Zaire + Zaïre + + + From a9a6e85aff99193058096e845b5f16bef8bfbc82 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 4 Feb 2015 18:15:37 +0000 Subject: [PATCH 10/28] [#8] Remove obsoletion messages from FileFormat list --- convert.py | 2 +- xml/FileFormat.xml | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/convert.py b/convert.py index 3616fe5e..bdfd219d 100644 --- a/convert.py +++ b/convert.py @@ -40,7 +40,7 @@ def indent(elem, level=0, shift=2): codelist_item = ET.Element('codelist-item') code = ET.Element('code') - code.text = registry_id + '/' + record.find('{http://www.iana.org/assignments}name').text + code.text = registry_id + '/' + record.find('{http://www.iana.org/assignments}name').text.split(' ')[0] codelist_item.append(code) category = ET.Element('category') diff --git a/xml/FileFormat.xml b/xml/FileFormat.xml index 416c61c4..cdc18755 100644 --- a/xml/FileFormat.xml +++ b/xml/FileFormat.xml @@ -1074,7 +1074,7 @@ application - application/smil - OBSOLETED in favor of application/smil+xml + application/smil application @@ -1370,7 +1370,7 @@ application - application/vnd.arastra.swi - OBSOLETED in favor of application/vnd.aristanetworks.swi + application/vnd.arastra.swi application @@ -2042,7 +2042,7 @@ application - application/vnd.geocube+xml - OBSOLETED by request + application/vnd.geocube+xml application @@ -2078,7 +2078,7 @@ application - application/vnd.gmx - DEPRECATED + application/vnd.gmx application @@ -2290,7 +2290,7 @@ application - application/vnd.informix-visionary - OBSOLETED in favor of application/vnd.visionary + application/vnd.informix-visionary application @@ -2930,7 +2930,7 @@ application - application/vnd.nokia.n-gage.symbian.install - OBSOLETE; no replacement given + application/vnd.nokia.n-gage.symbian.install application @@ -4434,7 +4434,7 @@ application - application/xhtml-voice+xml - OBSOLETE; no replacement given + application/xhtml-voice+xml application @@ -5022,7 +5022,7 @@ audio - audio/vnd.qcelp - DEPRECATED in favor of audio/qcelp + audio/vnd.qcelp audio @@ -5286,7 +5286,7 @@ message - message/news - OBSOLETED by RFC5537 + message/news message @@ -5314,7 +5314,7 @@ message - message/vnd.si.simp - OBSOLETED by request + message/vnd.si.simp message @@ -5486,7 +5486,7 @@ text - text/directory - DEPRECATED by RFC6350 + text/directory text @@ -5494,7 +5494,7 @@ text - text/ecmascript - OBSOLETED in favor of application/ecmascript + text/ecmascript text @@ -5522,7 +5522,7 @@ text - text/javascript - OBSOLETED in favor of application/javascript + text/javascript text @@ -5530,7 +5530,7 @@ text - text/markdown (TEMPORARY - registered 2014-11-11, expires 2015-11-11) + text/markdown text @@ -5706,7 +5706,7 @@ text - text/vnd.si.uricatalogue - OBSOLETED by request + text/vnd.si.uricatalogue text From a5ec422bd3344d9d733902406520715b34fb7e92 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Thu, 19 Feb 2015 16:35:49 +0000 Subject: [PATCH 11/28] [#51] Fix typo --- templates/Currency.xml | 2 +- xml/Currency.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/Currency.xml b/templates/Currency.xml index ccae0bad..13e32880 100644 --- a/templates/Currency.xml +++ b/templates/Currency.xml @@ -1,7 +1,7 @@ - >Currency + Currency ISO 4217 Currency used for all transactions and budgets diff --git a/xml/Currency.xml b/xml/Currency.xml index 26af7a43..935f1a1f 100644 --- a/xml/Currency.xml +++ b/xml/Currency.xml @@ -1,7 +1,7 @@ - >Currency + Currency ISO 4217 Currency used for all transactions and budgets From 5de586f56570d01720a285196a3fd4643cfd35db Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Fri, 27 Feb 2015 10:44:16 +0000 Subject: [PATCH 12/28] [#9] Remove historic 2 letter codes from Country list 4 letter codes should be used instead. --- convert.py | 1 - xml/Country.xml | 232 ------------------------------------------------ 2 files changed, 233 deletions(-) diff --git a/convert.py b/convert.py index bdfd219d..14fb1770 100644 --- a/convert.py +++ b/convert.py @@ -103,7 +103,6 @@ def add_code(code_text, country, withdrawn): # Ensure that historic codes come after current codes for country in countries.findall('country'): if country.find('status').text in ['formerly-used', 'transitionally-reserved']: - add_code(country.find('alpha-2-code').text, country, country.find('validity-end-date').text) add_code(country.find('alpha-4-code').text, country, country.find('validity-end-date').text) indent(template.getroot(), 0, 4) diff --git a/xml/Country.xml b/xml/Country.xml index f68cdc78..fbe4174e 100644 --- a/xml/Country.xml +++ b/xml/Country.xml @@ -2728,14 +2728,6 @@ the Republic of Zimbabwe - - AI - - French Afars and Issas - Afars et Issas - - - AIDJ @@ -2744,14 +2736,6 @@ - - AN - - Antilles néerlandaises (les ) - Netherlands Antilles - - - ANHH @@ -2760,14 +2744,6 @@ - - BQ - - British Antarctic Territory - Antarctique, Territoire britannique de l' - - - BQAQ @@ -2776,14 +2752,6 @@ - - BU - - Burma - Birmanie - - - BUMM @@ -2792,14 +2760,6 @@ - - BY - - Byelorussian SSR - Biélorussie, RSS de - - - BYAA @@ -2808,14 +2768,6 @@ - - CS - - Serbia and Montenegro - Serbie-et-Monténégro - - - CSXX @@ -2824,14 +2776,6 @@ - - CS - - Czechoslovakia - Tchécoslovaquie - - - CSHH @@ -2840,14 +2784,6 @@ - - CT - - Canton and Enderbury Islands - Canton et Enderbury, Îles - - - CTKI @@ -2856,14 +2792,6 @@ - - DD - - German Democratic Republic - Allemande, République démocratique - - - DDDE @@ -2872,14 +2800,6 @@ - - DY - - Dahomey - Dahomey - - - DYBJ @@ -2888,14 +2808,6 @@ - - FQ - - French Southern and Antarctic Territories - Australes et Antarctiques françaises, Terres - - - FQHH @@ -2904,14 +2816,6 @@ - - GE - - Gilbert et Ellice, Îles - Gilbert and Ellice Islands - - - GEHH @@ -2920,14 +2824,6 @@ - - HV - - Upper Volta - Haute-Volta - - - HVBF @@ -2936,14 +2832,6 @@ - - JT - - Johnston Island - Johnston, Île - - - JTUM @@ -2952,14 +2840,6 @@ - - MI - - Midway Islands - Midway, Îles - - - MIUM @@ -2968,14 +2848,6 @@ - - NH - - New Hebrides - Nouvelles-Hébrides - - - NHVU @@ -2984,14 +2856,6 @@ - - NQ - - Dronning Maud Land - Terre de la Reine Maud - - - NQAQ @@ -3000,14 +2864,6 @@ - - NT - - Neutral Zone - Zone neutre - - - NTHH @@ -3016,14 +2872,6 @@ - - PC - - Pacific Islands (Trust Territory) - Pacifique, Îles du (territoire sous tutelle) - - - PCHH @@ -3032,14 +2880,6 @@ - - PU - - United States Miscellaneous Pacific Islands - Pacifique, Diverses îles du (États-Unis) - - - PUUM @@ -3048,14 +2888,6 @@ - - PZ - - Panama Canal Zone - Panama, Zone du Canal de - - - PZPA @@ -3064,14 +2896,6 @@ - - RH - - Southern Rhodesia - Rhodésie du Sud - - - RHZW @@ -3080,14 +2904,6 @@ - - SK - - Sikkim - Sikkim - - - SKIN @@ -3096,14 +2912,6 @@ - - TP - - East Timor - Timor oriental - - - TPTL @@ -3112,14 +2920,6 @@ - - VD - - Viet-Nam, Democratic Republic of - Viet-Nam, République démocratique du - - - VDVN @@ -3128,14 +2928,6 @@ - - WK - - Wake, Île de - Wake Island - - - WKUM @@ -3144,14 +2936,6 @@ - - YD - - Yémen démocratique - Yemen, Democratic - - - YDYE @@ -3160,14 +2944,6 @@ - - YU - - Yougoslavie - Yugoslavia - - - YUCS @@ -3176,14 +2952,6 @@ - - ZR - - Zaire - Zaïre - - - ZRCD From 341e47192536c31a4122146ae9d3f5657edacbea Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 13 Jul 2017 09:05:32 +0100 Subject: [PATCH 13/28] Fix whitespace --- templates/Currency.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/Currency.xml b/templates/Currency.xml index 13e32880..ebf525b9 100644 --- a/templates/Currency.xml +++ b/templates/Currency.xml @@ -1,4 +1,4 @@ - + Currency From 0d6c85e775c403574e30ec8a868e291fcc33a522 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 30 Aug 2017 10:54:34 +0100 Subject: [PATCH 14/28] Add description to country codelist template --- templates/Country.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/templates/Country.xml b/templates/Country.xml index 32ccbefc..936fbb5c 100644 --- a/templates/Country.xml +++ b/templates/Country.xml @@ -3,6 +3,15 @@ Country + + + The Country codelist is generated from the ISO 3166-1 part of the + ISO 3166 standard. The standard makes allowance, alongside the + officially assigned codes, for code elements to be expanded by + using either reserved codes or user-assigned codes. IATI currently + defines additional codes in the XA -XZ range. + + http://www.iso.org/iso/home/standards/country_codes.htm From a31ba9717f00ce998d6d7714f49607af52d1ee64 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 30 Aug 2017 10:55:56 +0100 Subject: [PATCH 15/28] Add a bunch more codelist templates --- templates/AidType-category.xml | 12 ++++++++++++ templates/AidType.xml | 9 +++++++++ templates/CRSChannelCode.xml | 9 +++++++++ templates/CollaborationType.xml | 9 +++++++++ templates/FinanceType-category.xml | 12 ++++++++++++ templates/FinanceType.xml | 12 ++++++++++++ templates/FlowType.xml | 12 ++++++++++++ templates/Language.xml | 9 +++++++++ templates/Region.xml | 9 +++++++++ templates/Sector.xml | 9 +++++++++ templates/SectorCategory.xml | 9 +++++++++ templates/generic-codelist-item.xml | 12 ++++++++++++ 12 files changed, 123 insertions(+) create mode 100644 templates/AidType-category.xml create mode 100644 templates/AidType.xml create mode 100644 templates/CRSChannelCode.xml create mode 100644 templates/CollaborationType.xml create mode 100644 templates/FinanceType-category.xml create mode 100644 templates/FinanceType.xml create mode 100644 templates/FlowType.xml create mode 100644 templates/Language.xml create mode 100644 templates/Region.xml create mode 100644 templates/Sector.xml create mode 100644 templates/SectorCategory.xml create mode 100644 templates/generic-codelist-item.xml diff --git a/templates/AidType-category.xml b/templates/AidType-category.xml new file mode 100644 index 00000000..6e41b198 --- /dev/null +++ b/templates/AidType-category.xml @@ -0,0 +1,12 @@ + + + + Aid Type (category) + + + This codelists exists to group the Aid Type codelist into categories. It is not used as a codelist in its own right. + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/AidType.xml b/templates/AidType.xml new file mode 100644 index 00000000..e38a301e --- /dev/null +++ b/templates/AidType.xml @@ -0,0 +1,9 @@ + + + + Aid Type + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/CRSChannelCode.xml b/templates/CRSChannelCode.xml new file mode 100644 index 00000000..097e1ef7 --- /dev/null +++ b/templates/CRSChannelCode.xml @@ -0,0 +1,9 @@ + + + + CRS Channel Code + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/CollaborationType.xml b/templates/CollaborationType.xml new file mode 100644 index 00000000..1c7b9f7b --- /dev/null +++ b/templates/CollaborationType.xml @@ -0,0 +1,9 @@ + + + + Collaboration Type + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/FinanceType-category.xml b/templates/FinanceType-category.xml new file mode 100644 index 00000000..d20b1381 --- /dev/null +++ b/templates/FinanceType-category.xml @@ -0,0 +1,12 @@ + + + + Finance Type (category) + + + This codelists exists to group the Finance Type codelist into categories. It is not used as a codelist in its own right. + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/FinanceType.xml b/templates/FinanceType.xml new file mode 100644 index 00000000..ac53792a --- /dev/null +++ b/templates/FinanceType.xml @@ -0,0 +1,12 @@ + + + + Finance Type + + + DAC/CRS transaction classification used to distinguish financial instruments, e.g. grants or loans. + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/FlowType.xml b/templates/FlowType.xml new file mode 100644 index 00000000..e5fbae4f --- /dev/null +++ b/templates/FlowType.xml @@ -0,0 +1,12 @@ + + + + Flow Type + + + DAC/CRS distinction between ODA (official development assistance) and other types of resource flow. + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/Language.xml b/templates/Language.xml new file mode 100644 index 00000000..0649cfdb --- /dev/null +++ b/templates/Language.xml @@ -0,0 +1,9 @@ + + + + Language + + http://www.iso.org/iso/home/standards/language_codes.htm + + + diff --git a/templates/Region.xml b/templates/Region.xml new file mode 100644 index 00000000..bc1b1be4 --- /dev/null +++ b/templates/Region.xml @@ -0,0 +1,9 @@ + + + + Region + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/Sector.xml b/templates/Sector.xml new file mode 100644 index 00000000..43d98788 --- /dev/null +++ b/templates/Sector.xml @@ -0,0 +1,9 @@ + + + + DAC 5 Digit Sector + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/SectorCategory.xml b/templates/SectorCategory.xml new file mode 100644 index 00000000..fdaaab5e --- /dev/null +++ b/templates/SectorCategory.xml @@ -0,0 +1,9 @@ + + + + DAC 3 Digit Sector + + http://www.oecd.org/dac/stats/dacandcrscodelists.htm + + + diff --git a/templates/generic-codelist-item.xml b/templates/generic-codelist-item.xml new file mode 100644 index 00000000..9315797b --- /dev/null +++ b/templates/generic-codelist-item.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From 57aeb3c75416bd4de7c12f766413c41d53cc014a Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 30 Aug 2017 10:56:14 +0100 Subject: [PATCH 16/28] Fetch lots of source CSVs from github.com/datasets --- get.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/get.sh b/get.sh index 45669ca7..e93a72a8 100755 --- a/get.sh +++ b/get.sh @@ -1,4 +1,25 @@ mkdir source -wget "https://www.iana.org/assignments/media-types/media-types.xml" -O source/media-types.xml -wget "http://www.currency-iso.org/dam/downloads/table_a1.xml" -O source/table_a1.xml -wget "http://www.currency-iso.org/dam/downloads/table_a3.xml" -O source/table_a3.xml + +# IANA +wget "https://raw.githubusercontent.com/datasets/media-types/master/media-types.csv" -O source/media-types.csv + +# ISO 4217 +wget "https://raw.githubusercontent.com/datasets/currency-codes/master/data/codes-all.csv" -O source/currencies.csv + +# ISO 3166 +wget "https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv" -O source/countries.csv + +# ISO 639-1 +wget "https://raw.githubusercontent.com/datasets/language-codes/master/data/language-codes-full.csv" -O source/languages.csv + +# DAC CRS +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/aid_types.csv" -O source/aid_types.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/aid_type_categories.csv" -O source/aid_type_categories.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/collaboration_types.csv" -O source/collaboration_types.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/channel_codes.csv" -O source/channel_codes.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/finance_types.csv" -O source/finance_types.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/finance_type_categories.csv" -O source/finance_type_categories.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/flow_types.csv" -O source/flow_types.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/recipients.csv" -O source/recipients.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/sectors.csv" -O source/sectors.csv +wget "https://raw.githubusercontent.com/datasets/dac-crs-codes/master/data/sector_categories.csv" -O source/sector_categories.csv From 79e66128e792abc3d2828fd61e5d67cd8705b42e Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 30 Aug 2017 11:21:33 +0100 Subject: [PATCH 17/28] Rewrite of the convert.py code This mostly handles withdrawals. It works for all DAC CRS codelists, but some of the others still need a bit of work. --- convert.py | 355 ++++++++++++++++++++++++++++------------------- requirements.txt | 1 + 2 files changed, 214 insertions(+), 142 deletions(-) diff --git a/convert.py b/convert.py index 14fb1770..459def0f 100644 --- a/convert.py +++ b/convert.py @@ -1,3 +1,14 @@ +from collections import OrderedDict +from datetime import date +from os import system +from os.path import join +import re +import shutil + +from lxml import etree as ET +import unicodecsv as csv + + """ Converts codelist files from external sources into the format used by IATI. @@ -5,159 +16,219 @@ Note not all external codelists are converted automatically yet. """ - -from lxml import etree as ET +etparser = ET.XMLParser(encoding='utf-8', remove_blank_text=True) +today = str(date.today()) # Adapted from code at http://effbot.org/zone/element-lib.htm def indent(elem, level=0, shift=2): - i = "\n" + level*" "*shift + i = '\n' + level * ' ' * shift if len(elem): if not elem.text or not elem.text.strip(): - elem.text = i + " "*shift + elem.text = i + ' ' * shift if not elem.tail or not elem.tail.strip(): - elem.tail = i + # hack to remove trailing newline + if level: + elem.tail = i for elem in elem: - indent(elem, level+1, shift) + indent(elem, level + 1, shift) if not elem.tail or not elem.tail.strip(): elem.tail = i else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i -""" - -IANA Media Types (FileFormat) - -""" - -template = ET.parse('templates/FileFormat.xml', ET.XMLParser(remove_blank_text=True)) -codelist_items = template.find('codelist-items') - -media_types = ET.parse('source/media-types.xml') -for registry in media_types.findall('{http://www.iana.org/assignments}registry'): - registry_id = registry.attrib['id'] - for record in registry.findall('{http://www.iana.org/assignments}record'): - codelist_item = ET.Element('codelist-item') - - code = ET.Element('code') - code.text = registry_id + '/' + record.find('{http://www.iana.org/assignments}name').text.split(' ')[0] - codelist_item.append(code) - - category = ET.Element('category') - category.text = registry_id - codelist_item.append(category) - - codelist_items.append(codelist_item) - -indent(template.getroot(), 0, 4) -template.write('xml/FileFormat.xml', pretty_print=True) - - - -""" - -ISO Country Alpha 2 - -""" - -XML_LANG = '{http://www.w3.org/XML/1998/namespace}lang' - -template = ET.parse('templates/Country.xml', ET.XMLParser(remove_blank_text=True)) -codelist_items = template.find('codelist-items') - -def add_code(code_text, country, withdrawn): - codelist_item = ET.Element('codelist-item') - - if withdrawn: - codelist_item.attrib['withdrawn'] = withdrawn - - code = ET.Element('code') - code.text = code_text - codelist_item.append(code) - - name = ET.Element('name') - codelist_item.append(name) - for short_name in country.findall('short-name'): - if XML_LANG in short_name.attrib: - narrative = ET.Element('narrative') - narrative.attrib[XML_LANG] = short_name.attrib[XML_LANG] - narrative.text = short_name.text - name.append(narrative) - - description = ET.Element('description') - codelist_item.append(description) - for full_name in country.findall('full-name'): - if XML_LANG in full_name.attrib: - narrative = ET.Element('narrative') - narrative.attrib[XML_LANG] = full_name.attrib[XML_LANG] - narrative.text = full_name.text - description.append(narrative) - - codelist_items.append(codelist_item) - -countries = ET.parse('source/iso_country_codes.xml') -for country in countries.findall('country'): - if country.find('status').text == 'officially-assigned': - add_code(country.find('alpha-2-code').text, country, None) - -# Ensure that historic codes come after current codes -for country in countries.findall('country'): - if country.find('status').text in ['formerly-used', 'transitionally-reserved']: - add_code(country.find('alpha-4-code').text, country, country.find('validity-end-date').text) - -indent(template.getroot(), 0, 4) -template.write('xml/Country.xml', pretty_print=True) - - - -""" - -ISO Currency Alpha Code - -""" - -template = ET.parse('templates/Currency.xml', ET.XMLParser(remove_blank_text=True)) -codelist_items = template.find('codelist-items') - -currency_codes = {} -for source_filename, historic in [ ('source/table_a1.xml', False), ('source/table_a3.xml', True) ]: - country_currency_xml = ET.parse(source_filename) - if historic: - country_currencies = country_currency_xml.find('HstrcCcyTbl').findall('HstrcCcyNtry') - else: - country_currencies = country_currency_xml.find('CcyTbl').findall('CcyNtry') - for country_currency in country_currencies: - currency_name = country_currency.find('CcyNm').text - if currency_name == 'No universal currency': - continue - currency_code = country_currency.find('Ccy').text - if currency_code in currency_codes: - if not currency_codes[currency_code][0] == currency_name: - print 'Duplicate found for code {}, using name "{}" instead of name "{}" because it occurs first'.format(currency_code, currency_codes[currency_code], currency_name) +def str_update(current, proposed): + if current and re.split(r'[\s|\xa0]+', current) == re.split(r'[\s|\xa0]+', proposed): + return current + elif proposed: + return proposed.replace('\r', '').replace('. ', '. ').strip() + return None + +def create_codelist_item(keys): + tmpl_path = join('templates', 'generic-codelist-item.xml') + xml = ET.parse(tmpl_path, etparser).getroot() + if 'name_en' not in keys: + xml.remove(xml.find('name')) + if 'description_en' not in keys: + xml.remove(xml.find('description')) + if 'category' not in keys: + xml.remove(xml.find('category')) + return xml + +def update_codelist_item(codelist_item, code_dict): + # update code + if not codelist_item.find('code').text: + codelist_item.find('code').text = code_dict['code'] + if 'category' in code_dict: + # update category + codelist_item.find('category').text = code_dict['category'] + + if 'name_en' in code_dict: + for name_el in codelist_item.findall('name/narrative'): + if name_el.get('{http://www.w3.org/XML/1998/namespace}lang') == 'fr': + name_el.text = str_update(name_el.text, code_dict.get('name_fr')) + else: + name_el.text = str_update(name_el.text, code_dict.get('name_en')) + + if 'description_en' in code_dict: + for description_el in codelist_item.findall('description/narrative'): + if description_el.get('{http://www.w3.org/XML/1998/namespace}lang') == 'fr': + if code_dict['description_fr']: + description_el.text = str_update(description_el.text, code_dict['description_fr']) + else: + codelist_item.remove(description_el) + else: + description_el.text = str_update(description_el.text, code_dict['description_en']) + + return codelist_item + +def source_to_xml(tmpl_name, source_name, lookup, source_data=None): + old_xml = ET.parse(join('xml', '{}.xml'.format(tmpl_name)), etparser) + + tmpl_path = join('templates', '{}.xml'.format(tmpl_name)) + xml = ET.parse(tmpl_path, etparser) + codelist_items = xml.find('codelist-items') + + if not source_data: + source_path = join('source', '{}.csv'.format(source_name)) + with open(source_path) as f: + reader = csv.DictReader(f) + source_data = [{ + k: x.get(v) for k, v in lookup.items() + } for x in reader if x[lookup['code']]] + + source_data_dict = OrderedDict([(source_data_row['code'].upper(), source_data_row) for source_data_row in source_data]) + + old_codelist_els = old_xml.xpath('//codelist-item') + while old_codelist_els: + old_codelist_el = old_codelist_els.pop(0) + old_codelist_code = old_codelist_el.find('code').text.upper() + # peek at the first code + if source_data_dict: + new_code_dict = source_data_dict.values()[0] + if new_code_dict['code'].upper() != old_codelist_code and not old_xml.xpath('//codelist-item/code[text()="{}"]/..'.format(new_code_dict['code'])): + # add a new code, with activation date of today + new_codelist_item = create_codelist_item(new_code_dict.keys()) + new_codelist_item = update_codelist_item(new_codelist_item, new_code_dict) + new_codelist_item.attrib['status'] = 'active' + new_codelist_item.attrib['activation-date'] = today + codelist_items.append(new_codelist_item) + source_data_dict.popitem(last=False) + # push the last popped item onto the front of the queue + old_codelist_els.insert(0, old_codelist_el) + continue + + if old_codelist_code in source_data_dict: + # it's in the current codes, so update it + new_code_dict = source_data_dict[old_codelist_code] + updated_codelist_item = update_codelist_item(old_codelist_el, new_code_dict) + codelist_items.append(updated_codelist_item) + del source_data_dict[old_codelist_code] + elif old_codelist_el.attrib.get('status') == 'withdrawn': + # it's an old withdrawn code, so just copy it + codelist_items.append(old_codelist_el) + elif codelist_items.xpath('//codelist-item/code[text()="{}"]/..'.format(old_codelist_el.find('code').text)): + # some codelist items are hard-coded, and should just + # be left as is + pass else: - currency_codes[currency_code] = (currency_name, country_currency.find('WthdrwlDt').text if historic else None) - -# Ensure that historic codes come after current codes -for histroic_section in [False, True]: - for currency_code, (currency_name, withdrawal_date) in sorted(currency_codes.items()): - if (withdrawal_date is None) == histroic_section: - continue - codelist_item = ET.Element('codelist-item') - if withdrawal_date: - codelist_item.attrib['withdrawn'] = withdrawal_date - - code = ET.Element('code') - code.text = currency_code - codelist_item.append(code) - - name = ET.Element('name') - codelist_item.append(name) - narrative = ET.Element('narrative') - narrative.text = currency_name - name.append(narrative) - - codelist_items.append(codelist_item) - -indent(template.getroot(), 0, 4) -template.write('xml/Currency.xml', pretty_print=True) - + # it's a newly withdrawn code, so mark the withdrawal date + # as today, and copy it + old_codelist_el.attrib['status'] = 'withdrawn' + old_codelist_el.attrib['withdrawal-date'] = today + codelist_items.append(old_codelist_el) + + output_path = join('xml', '{}.xml'.format(tmpl_name)) + for el in xml.iter('*'): + if el.text is not None: + if not el.text.strip(): + # force tag self-escaping + el.text = None + indent(xml.getroot(), 0, 4) + xml.write(output_path, encoding='utf-8', pretty_print=True) + +# throw away any local changes +system('git checkout -- xml/') + +fileformat_lookup = { + 'code': 'Media Type', + 'category': 'Type', +} +source_to_xml('FileFormat', 'media-types', fileformat_lookup) + +currency_lookup = { + 'code': 'AlphabeticCode', + 'name_en': 'Currency', + 'withdrawal_date': 'WithdrawalDate', +} +# TODO: source data includes withdrawn codes! +# This needs to be factored in when parsing. +source_to_xml('Currency', 'currencies', currency_lookup) + +country_lookup = { + 'code': 'code', + 'name_en': 'name_en', +} +source_path = join('source', 'countries.csv') +with open(source_path) as f: + reader = csv.DictReader(f) + countries = [{ + 'code': x['ISO3166-1-Alpha-2'], + 'name_en': x['name'].upper(), + } for x in reader] +source_to_xml('Country', 'countries', country_lookup, source_data=countries) + +language_lookup = { + 'code': 'alpha2', + 'name_en': 'English', +} +source_to_xml('Language', 'languages', language_lookup) + +lookup_no_category = { + 'code': 'code', + 'name_en': 'name_en', + 'name_fr': 'name_fr', + 'description_en': 'description_en', + 'description_fr': 'description_fr', +} +source_to_xml('AidType-category', 'aid_type_categories', lookup_no_category) +source_to_xml('FlowType', 'flow_types', lookup_no_category) +source_to_xml('SectorCategory', 'sector_categories', lookup_no_category) + +lookup_no_desc = { + 'code': 'code', + 'name_en': 'name_en', + 'name_fr': 'name_fr', +} +source_to_xml('CollaborationType', 'collaboration_types', lookup_no_desc) +source_to_xml('CRSChannelCode', 'channel_codes', lookup_no_desc) +source_to_xml('FinanceType-category', 'finance_type_categories', lookup_no_desc) + +lookup = { + 'code': 'code', + 'category': 'category', + 'name_en': 'name_en', + 'name_fr': 'name_fr', + 'description_en': 'description_en', + 'description_fr': 'description_fr', +} +source_to_xml('AidType', 'aid_types', lookup) +source_to_xml('FinanceType', 'finance_types', lookup) + +source_path = join('source', 'sectors.csv') +with open(source_path) as f: + reader = csv.DictReader(f) + sectors = [] + for sector in reader: + if sector['voluntary_code'] != '': + sector['code'] = sector['voluntary_code'] + sectors.append(sector) +sectors = sorted(sectors, key=lambda x: x['code']) +source_to_xml('Sector', None, lookup, source_data=sectors) + +# source_to_xml('Region', 'region') +source_path = join('source', 'recipients.csv') +with open(source_path) as f: + reader = csv.DictReader(f) + regions = [x for x in reader if x['income_group'] == ''] +source_to_xml('Region', None, lookup, source_data=regions) diff --git a/requirements.txt b/requirements.txt index 7b403f33..10e6d209 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ lxml==3.4.1 +unicodecsv==0.14.1 From 5b6bba5afaade282720bd234e43e65e215037322 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Fri, 27 Oct 2017 16:42:32 +0100 Subject: [PATCH 18/28] Some linting fixes --- convert.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/convert.py b/convert.py index 459def0f..2bff1eee 100644 --- a/convert.py +++ b/convert.py @@ -3,7 +3,6 @@ from os import system from os.path import join import re -import shutil from lxml import etree as ET import unicodecsv as csv @@ -19,6 +18,7 @@ etparser = ET.XMLParser(encoding='utf-8', remove_blank_text=True) today = str(date.today()) + # Adapted from code at http://effbot.org/zone/element-lib.htm def indent(elem, level=0, shift=2): i = '\n' + level * ' ' * shift @@ -37,6 +37,7 @@ def indent(elem, level=0, shift=2): if level and (not elem.tail or not elem.tail.strip()): elem.tail = i + def str_update(current, proposed): if current and re.split(r'[\s|\xa0]+', current) == re.split(r'[\s|\xa0]+', proposed): return current @@ -44,6 +45,7 @@ def str_update(current, proposed): return proposed.replace('\r', '').replace('. ', '. ').strip() return None + def create_codelist_item(keys): tmpl_path = join('templates', 'generic-codelist-item.xml') xml = ET.parse(tmpl_path, etparser).getroot() @@ -55,6 +57,7 @@ def create_codelist_item(keys): xml.remove(xml.find('category')) return xml + def update_codelist_item(codelist_item, code_dict): # update code if not codelist_item.find('code').text: @@ -82,6 +85,7 @@ def update_codelist_item(codelist_item, code_dict): return codelist_item + def source_to_xml(tmpl_name, source_name, lookup, source_data=None): old_xml = ET.parse(join('xml', '{}.xml'.format(tmpl_name)), etparser) @@ -147,6 +151,7 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): indent(xml.getroot(), 0, 4) xml.write(output_path, encoding='utf-8', pretty_print=True) + # throw away any local changes system('git checkout -- xml/') @@ -202,7 +207,8 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): } source_to_xml('CollaborationType', 'collaboration_types', lookup_no_desc) source_to_xml('CRSChannelCode', 'channel_codes', lookup_no_desc) -source_to_xml('FinanceType-category', 'finance_type_categories', lookup_no_desc) +source_to_xml('FinanceType-category', 'finance_type_categories', + lookup_no_desc) lookup = { 'code': 'code', From 1aab997c1342c004c1e10be64858bbe4ba9e0ee9 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Fri, 5 Jan 2018 18:32:53 +0000 Subject: [PATCH 19/28] Country codes dataset changed a bit --- convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.py b/convert.py index 2bff1eee..fd606252 100644 --- a/convert.py +++ b/convert.py @@ -179,7 +179,7 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): reader = csv.DictReader(f) countries = [{ 'code': x['ISO3166-1-Alpha-2'], - 'name_en': x['name'].upper(), + 'name_en': x['official_name_en'].upper(), } for x in reader] source_to_xml('Country', 'countries', country_lookup, source_data=countries) From f7a21d3b1be035dbddbefa4a9e26ebc186432b6f Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Sat, 6 Jan 2018 13:26:23 +0000 Subject: [PATCH 20/28] Ignore countries with no country code --- convert.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convert.py b/convert.py index fd606252..c2e4638f 100644 --- a/convert.py +++ b/convert.py @@ -179,8 +179,8 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): reader = csv.DictReader(f) countries = [{ 'code': x['ISO3166-1-Alpha-2'], - 'name_en': x['official_name_en'].upper(), - } for x in reader] + 'name_en': x['CLDR display name'].upper(), + } for x in reader if x['ISO3166-1-Alpha-2']] source_to_xml('Country', 'countries', country_lookup, source_data=countries) language_lookup = { From e9b3590ec181ec886f3161575326d0c2242871d9 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Sat, 6 Jan 2018 14:45:44 +0000 Subject: [PATCH 21/28] Ignore finance type category 0 --- convert.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/convert.py b/convert.py index c2e4638f..3e8c8080 100644 --- a/convert.py +++ b/convert.py @@ -207,8 +207,16 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): } source_to_xml('CollaborationType', 'collaboration_types', lookup_no_desc) source_to_xml('CRSChannelCode', 'channel_codes', lookup_no_desc) -source_to_xml('FinanceType-category', 'finance_type_categories', - lookup_no_desc) + +source_path = join('source', 'finance_type_categories.csv') +with open(source_path) as f: + reader = csv.DictReader(f) + finance_type_categories = [] + for finance_type_category in reader: + if finance_type_category['code'] == '0': + continue + finance_type_categories.append(finance_type_category) +source_to_xml('FinanceType-category', None, lookup_no_desc, source_data=finance_type_categories) lookup = { 'code': 'code', @@ -219,7 +227,16 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): 'description_fr': 'description_fr', } source_to_xml('AidType', 'aid_types', lookup) -source_to_xml('FinanceType', 'finance_types', lookup) + +source_path = join('source', 'finance_types.csv') +with open(source_path) as f: + reader = csv.DictReader(f) + finance_types = [] + for finance_type in reader: + if finance_type['category'] == '0': + continue + finance_types.append(finance_type) +source_to_xml('FinanceType', None, lookup, source_data=finance_types) source_path = join('source', 'sectors.csv') with open(source_path) as f: From 0811e1801e7a4ce2ac5c1f08da6ac76572f6c779 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Sat, 6 Jan 2018 14:46:09 +0000 Subject: [PATCH 22/28] When finance type name is missing, use description --- convert.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/convert.py b/convert.py index 3e8c8080..41290b8c 100644 --- a/convert.py +++ b/convert.py @@ -235,6 +235,10 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): for finance_type in reader: if finance_type['category'] == '0': continue + if finance_type['name_en'] == '': + finance_type['name_en'] = finance_type['description_en'] + if finance_type['name_fr'] == '': + finance_type['name_fr'] = finance_type['description_fr'] finance_types.append(finance_type) source_to_xml('FinanceType', None, lookup, source_data=finance_types) From c7adab039dd7be7a9546de94c44ca1abc1790fdd Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Sat, 6 Jan 2018 14:46:44 +0000 Subject: [PATCH 23/28] Remove multiple spaces in sector name/description --- convert.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/convert.py b/convert.py index 41290b8c..d3a47cf9 100644 --- a/convert.py +++ b/convert.py @@ -249,6 +249,8 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): for sector in reader: if sector['voluntary_code'] != '': sector['code'] = sector['voluntary_code'] + for txt in ['name_en', 'name_fr', 'description_en', 'description_fr']: + sector[txt] = re.sub(r' +', ' ', sector[txt]) sectors.append(sector) sectors = sorted(sectors, key=lambda x: x['code']) source_to_xml('Sector', None, lookup, source_data=sectors) From 48a857bc8a079c80c6d2d56b9f7707af33829e69 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Sat, 6 Jan 2018 14:47:24 +0000 Subject: [PATCH 24/28] Remove old, commented out code --- convert.py | 1 - 1 file changed, 1 deletion(-) diff --git a/convert.py b/convert.py index d3a47cf9..b1f385fb 100644 --- a/convert.py +++ b/convert.py @@ -255,7 +255,6 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): sectors = sorted(sectors, key=lambda x: x['code']) source_to_xml('Sector', None, lookup, source_data=sectors) -# source_to_xml('Region', 'region') source_path = join('source', 'recipients.csv') with open(source_path) as f: reader = csv.DictReader(f) From bf450e81611b5f3fdcc78b60d292929cf1c2ffc0 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 7 Nov 2018 11:11:47 +0000 Subject: [PATCH 25/28] Bugfix --- convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.py b/convert.py index b1f385fb..f3111b53 100644 --- a/convert.py +++ b/convert.py @@ -79,7 +79,7 @@ def update_codelist_item(codelist_item, code_dict): if code_dict['description_fr']: description_el.text = str_update(description_el.text, code_dict['description_fr']) else: - codelist_item.remove(description_el) + codelist_item.find('description').remove(description_el) else: description_el.text = str_update(description_el.text, code_dict['description_en']) From 52074bc8a51e635c5015559647c309484f99e3fb Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 7 Nov 2018 11:11:57 +0000 Subject: [PATCH 26/28] python3-related change --- convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.py b/convert.py index f3111b53..eaa9f1f9 100644 --- a/convert.py +++ b/convert.py @@ -109,7 +109,7 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): old_codelist_code = old_codelist_el.find('code').text.upper() # peek at the first code if source_data_dict: - new_code_dict = source_data_dict.values()[0] + new_code_dict = list(source_data_dict.values())[0] if new_code_dict['code'].upper() != old_codelist_code and not old_xml.xpath('//codelist-item/code[text()="{}"]/..'.format(new_code_dict['code'])): # add a new code, with activation date of today new_codelist_item = create_codelist_item(new_code_dict.keys()) From ed7840a4789aa592522581987a9ca34cba9762a1 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 7 Nov 2018 11:12:15 +0000 Subject: [PATCH 27/28] Country codes are no longer upper cased in IATI --- convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.py b/convert.py index eaa9f1f9..10204182 100644 --- a/convert.py +++ b/convert.py @@ -179,7 +179,7 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): reader = csv.DictReader(f) countries = [{ 'code': x['ISO3166-1-Alpha-2'], - 'name_en': x['CLDR display name'].upper(), + 'name_en': x['CLDR display name'], } for x in reader if x['ISO3166-1-Alpha-2']] source_to_xml('Country', 'countries', country_lookup, source_data=countries) From 338205d4a278b33ff27f82556a611da725ce85d5 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 7 Nov 2018 11:12:48 +0000 Subject: [PATCH 28/28] Fix to reflect change in source data --- convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.py b/convert.py index 10204182..a7a44688 100644 --- a/convert.py +++ b/convert.py @@ -258,5 +258,5 @@ def source_to_xml(tmpl_name, source_name, lookup, source_data=None): source_path = join('source', 'recipients.csv') with open(source_path) as f: reader = csv.DictReader(f) - regions = [x for x in reader if x['income_group'] == ''] + regions = [x for x in reader if x['income_group'] == 'Unallocated by income'] source_to_xml('Region', None, lookup, source_data=regions)