diff --git a/README.md b/README.md index 1f9a754..70e8c90 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Geoconvert converts (obvious) data like zipcode, postcode, address, country name French department name, Americain state name, Canadian province or territory name to generic data. -* Languages available for country names: deutsch, english, french, portuguese. +* Languages available for country names: deutsch, english, french, portuguese, spanish. * Languages available for capital names: deutsch, english, french. Support Python 3.6, 3.7, 3.8 and 3.9. @@ -38,6 +38,8 @@ pip install https://github.com/jurismarches/geoconvert/archive/master.zip 'EG' >>> address_to_country_code("Bem vindo ao Afeganistão") # PT 'AF' +>>> address_to_country_code("Bienvenidos a Nueva Zelanda") # ES +'NZ' >>> address_to_subdivision_code("2 pl. Saint-Pierre, 44000 Nantes, France") # FR '44' >>> address_to_subdivision_code("2 pl. Saint-Pierre, 44000 Nantes", country="FR") @@ -88,6 +90,8 @@ guess the country code: 'EG' >>> address_to_country_code("Bem vindo ao Afeganistão") # PT 'AF' +>>> address_to_country_code("Bienvenidos a Nueva Zelanda") # ES +'NZ' ``` @@ -103,6 +107,8 @@ for more efficiency (available choices: "de" for german, "en" for english, 'EG' >>> address_to_country_code("Bem vindo ao Afeganistão", lang="pt") 'AF' +>>> address_to_country_code("Bienvenidos a Nueva Zelanda", lang="es") +'NZ' ``` diff --git a/geoconvert/data/countries.py b/geoconvert/data/countries.py index ab69396..bbe5b6e 100644 --- a/geoconvert/data/countries.py +++ b/geoconvert/data/countries.py @@ -19,6 +19,7 @@ "congo": "CG", # en, fr } + countries_fr = { **special_countries, **{ @@ -768,6 +769,7 @@ }, } + countries_pt = { **special_countries, **{ @@ -1021,11 +1023,275 @@ } +countries_es = { + **special_countries, + **{ + "afganistan": "AF", + "sudafrica": "ZA", + "islas aland": "AX", + "albania": "AL", + "alemania": "DE", + "andorra": "AD", + "angola": "AO", + "anguila": "AI", + "antartida": "AQ", + "antigua y barbuda": "AG", + "arabia saudita": "SA", + "argelia": "DZ", + "argentina": "AR", + "armenia": "AM", + "aruba": "AW", + "australia": "AU", + "austria": "AT", + "azerbaiyan": "AZ", + "bahamas": "BS", + "bahrein": "BH", + "bangladesh": "BD", + "barbados": "BB", + "belgica": "BE", + "belice": "BZ", + "benin": "BJ", + "bermudas": "BM", + "bielorrusia": "BY", + "bolivia": "BO", + "caribe neerlandes": "BQ", + "bosnia y herzegovina": "BA", + "botswana": "BW", + "isla bouvet": "BV", + "brasil": "BR", + "brunido": "BN", + "bulgaria": "BG", + "burkina faso": "BF", + "burundi": "BI", + "butan": "BT", + "butao": "BT", + "cabo verde": "CV", + "camboya": "KH", + "camerun": "CM", + "canada": "CA", + "islas caiman": "KY", + "kazajstan": "KZ", + "republica centroafricana": "CF", + "chad": "TD", + "cheki": "CZ", + "chile": "CL", + "china": "CN", + "chipre": "CY", + "isla de navidad": "CX", + "islas cocos keeling": "CC", + "colombia": "CO", + "comores": "KM", + "islas cook": "CK", + "corea del sur": "KR", + "corea del norte": "KP", + "costa de marfil": "CI", + "costa rica": "CR", + "croacia": "HR", + "cuba": "CU", + "curacao": "CW", + "curazao": "CW", + "dinamarca": "DK", + "djibouti": "DJ", + "dominica": "DM", + "republica dominicana": "DO", + "egipto": "EG", + "el salvador": "SV", + "emiratos arabes unidos": "AE", + "ecuador": "EC", + "eritrea": "ER", + "eslovaquia": "SK", + "eslovenia": "SI", + "espana": "ES", + "estados unidos": "US", + "estonia": "EE", + "etiopia": "ET", + "islas feroe": "FO", + "fiji": "FJ", + "fiyi": "FJ", + "filipinas": "PH", + "finlandia": "FI", + "francia": "FR", + "gabon": "GA", + "gambia": "GM", + "ghana": "GH", + "georgia": "GE", + "islas georgia del sur y islas sandwich del sur": "GS", + "islas georgia del sur y sandwich del sur": "GS", + "gibraltar": "GI", + "grecia": "GR", + "granada": "GD", + "groenlandia": "GL", + "guadalupe": "GP", + "guam": "GU", + "guatemala": "GT", + "guernsey": "GG", + "guayana": "GY", + "guayana francesa": "GF", + "guinea bissau": "GW", + "guinea": "GN", + "guinea ecuatorial": "GQ", + "haiti": "HT", + "islas heard y mcdonald": "HM", + "heard y mcdonald": "HM", + "honduras": "HN", + "hong kong": "HK", + "hungria": "HU", + "yemen": "YE", + "india": "IN", + "indonesia": "ID", + "irak": "IQ", + "iran": "IR", + "irlanda": "IE", + "islandia": "IS", + "israel": "IL", + "italia": "IT", + "jamaica": "JM", + "japon": "JP", + "jersey": "JE", + "jordan": "JO", + "kiribati": "KI", + "kuwait": "KW", + "laos": "LA", + "lesoto": "LS", + "letonia": "LV", + "libano": "LB", + "liberia": "LR", + "libia": "LY", + "liechtenstein": "LI", + "lituania": "LT", + "luxemburgo": "LU", + "macao": "MO", + "macedonia del norte": "MK", + "madagascar": "MG", + "malasia": "MY", + "malawi": "MW", + "maldivas": "MV", + "mali": "ML", + "malta": "MT", + "islas malvinas": "FK", + "isla de man": "IM", + "marianas del norte": "MP", + "marruecos": "MA", + "islas marshall": "MH", + "martinica": "MQ", + "mauricio": "MU", + "mauritania": "MR", + "mayotte": "YT", + "islas ultramarinas menores de los estados unidos": "UM", + "ultramarinas menores de los estados unidos": "UM", + "mexico": "MX", + "myanmar": "MM", + "estados federados de micronesia": "FM", + "mozambique": "MZ", + "moldavia": "MD", + "monaco": "MC", + "mongolia": "MN", + "montenegro": "ME", + "montserrat": "MS", + "namibia": "NA", + "nauru": "NR", + "nepal": "NP", + "nicaragua": "NI", + "niger": "NE", + "nigeria": "NG", + "niue": "NU", + "isla norfolk": "NF", + "norfolk": "NF", + "noruega": "NO", + "nueva caledonia": "NC", + "nueva zelanda": "NZ", + "oman": "OM", + "paises bajos": "NL", + "palaos": "PW", + "palestina": "PS", + "panama": "PA", + "papua nueva guinea": "PG", + "pakistan": "PK", + "paraguay": "PY", + "peru": "PE", + "pitcairn": "PN", + "islas pitcairn": "PN", + "polinesia francesa": "PF", + "polonia": "PL", + "puerto rico": "PR", + "portugal": "PT", + "katar": "QA", + "qatar": "QA", + "kenia": "KE", + "kirguistan": "KG", + "reino unido": "GB", + "reunion": "RE", + "rumania": "RO", + "ruanda": "RW", + "rusia": "RU", + "sahara occidental": "EH", + "samoa americana": "AS", + "samoa": "WS", + "san pedro y miquelon": "PM", + "islas salomon": "SB", + "san marino": "SM", + "santa elena ascension y tristan de acuna": "SH", + "santa lucia": "LC", + "san bartolome": "BL", + "san cristobal y nieves": "KN", + "san martin": "MF", + "santo tome y principe": "ST", + "san vicente y las granadinas": "VC", + "senegal": "SN", + "sierra leona": "SL", + "serbia": "RS", + "seychelles": "SC", + "singapur": "SG", + "siria": "SY", + "somalia": "SO", + "sri lanka": "LK", + "esuatini": "SZ", + "sudan": "SD", + "sudan del sur": "SS", + "suecia": "SE", + "suiza": "CH", + "surinam": "SR", + "svalbard y jan mayen": "SJ", + "tailandia": "TH", + "taiwan": "TW", + "tayikistan": "TJ", + "tanzania": "TZ", + "tierras australes y antarticas francesas": "TF", + "territorio britanico del oceano indico": "IO", + "timor oriental": "TL", + "togo": "TG", + "tokelau": "TK", + "tonga": "TO", + "trinidad y tobago": "TT", + "tunez": "TN", + "turcas y caicos": "TC", + "islas turcas y caicos": "TC", + "turkmenistan": "TM", + "turquia": "TR", + "tuvalu": "TV", + "ucrania": "UA", + "uganda": "UG", + "uruguay": "UY", + "uzbekistan": "UZ", + "vanuatu": "VU", + "vaticano": "VA", + "venezuela": "VE", + "vietnam": "VN", + "islas virgenes americanas": "VI", + "islas virgenes britanicas": "VG", + "wallis y futuna": "WF", + "zambia": "ZM", + "zimbabue": "ZW", + }, +} + + language_to_country_names = { "de": countries_de, "en": countries_en, "fr": countries_fr, "pt": countries_pt, + "es": countries_es, } @@ -1045,6 +1311,7 @@ "US": frozenset(["UM"]), } + # country_territories reciprocal territory_to_country = { territory: country diff --git a/test_geoconvert.py b/test_geoconvert.py index 49cdfdf..6dd2b7f 100644 --- a/test_geoconvert.py +++ b/test_geoconvert.py @@ -628,6 +628,30 @@ def test_country_name_to_country_code_pt(self, input_data, expected): assert country_name_to_country_code(input_data, lang="PT") == expected assert country_name_to_id(input_data, lang="PT") == expected + @pytest.mark.parametrize( + "input_data, expected", + [ + ("Los Emiratos Árabes Unidos", "AE"), + (" Islas Vírgenes Británicas ", "VG"), + ("Turkménistan\n", "TM"), + ("España!", "ES"), + ("Egipto", "EG"), + ("groenlandia", "GL"), + ("Camboya", "KH"), + ("Isla de Mauricio", "MU"), + ("San Cristóbal y Nieves", "KN"), + ("Nueva Zelanda", "NZ"), + ("Países Bajos ", "NL"), + ("Kirguistán", "KG"), + ("suiza", "CH"), + ("Tayikistán", "TJ"), + ("Tailandia", "TH"), + ], + ) + def test_country_name_to_country_code_es(self, input_data, expected): + assert country_name_to_country_code(input_data, lang="ES") == expected + assert country_name_to_id(input_data, lang="ES") == expected + @pytest.mark.parametrize( "input_data, kwargs, expected", [