Skip to content

Instantly share code, notes, and snippets.

@poxrud
Last active February 4, 2022 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poxrud/7782545 to your computer and use it in GitHub Desktop.
Save poxrud/7782545 to your computer and use it in GitHub Desktop.
Get a comma separated list of ISO 3166 Country Codes. (example: AF,AX,AL,DZ...)
require 'net/http'
uri = URI('https://pkgstore.datahub.io/core/country-list/data_csv/data/d7c9d7cfb42cb69f4422dec222dbbaa8/data_csv.csv')
countries = Net::HTTP.get(uri)
countries = countries.split("\r\n").drop(1)
countries = countries.map do |country|
country.split(",").last
end.join(",")
puts countries
@groovenectar
Copy link

FYI, this URL is outdated: http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.htm

I'm not sure of an alternative at the moment.

@poxrud
Copy link
Author

poxrud commented Feb 4, 2022

fixed with a new data URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment