Last active
August 29, 2015 14:02
-
-
Save k1ife/e7869b7035699460e1d8 to your computer and use it in GitHub Desktop.
getting from Geonames.org only needed countries with theirs own names and saveing them into my table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
@alternatename = [] | |
@currencyco = [] | |
@languageco = [] | |
@title = '' | |
@title_en = '' | |
@title_alt = '' | |
geonames = Mysql2::Client.new(:host => "localhost", :username => "root", :password => 'pass', :database => 'geonames') | |
countries = geonames.query("SELECT geonameId, fips_code, name, currency, languages FROM countryinfo") | |
countries.each do |country| | |
@countryco = country['geonameId'] | |
@title_en = country['name'] | |
alter = geonames.query("SELECT isoLanguage, alternateName, isPreferredName FROM alternatename WHERE geonameid = '#{@countryco}' ") | |
alter.each do |alt| | |
if alt['isoLanguage'] != 'en' && alt['isoLanguage'] != '' && alt['isoLanguage'] != 'wiki' && alt['isoLanguage'] != 'link' | |
@title_alt = @title_alt + ", " + alt['alternateName'].gsub(/'/, "`").gsub(/’/, "`") | |
end | |
end | |
@title = @title_en | |
@title_alt = @title_en + ", " + @title_alt | |
rsite = Mysql2::Client.new(:host => "localhost", :username => "root", :password => 'pass', :database => 'rsite_dev') | |
rsite.query(" INSERT INTO countries SET title = '#{@title}', title_en = '#{@title_en}', title_alt = '#{@title_alt}' ") | |
rsite.close | |
@alternatename = [] | |
@currencyco = [] | |
@languageco = [] | |
@title = '' | |
@title_en = '' | |
@title_alt = '' | |
end | |
geonames.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment