Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
christocracy committed May 9, 2008
1 parent 8af7cd8 commit 07e5858
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/geonames.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,3 +183,6 @@ def self.import_cities15000
end end
end end
end end



57 changes: 57 additions & 0 deletions tasks/geonames_tasks.rake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,8 +11,65 @@ namespace :geonames do
puts " Importing geonames " puts " Importing geonames "
puts "*************************************************************************************" puts "*************************************************************************************"


Resistor::Geonames.import
end

desc "Export geonames to /db"
task :export => :environment do
puts "*************************************************************************************"
puts " Exporting geonames to db/geonames.yml "
puts "*************************************************************************************"

output = {
:countries => [],
:regions => [],
:cities => []
}
cities = City.find(:all, :include => [:region])
regions = Region.find(:all, :include => [:country])
countries = Country.find(:all)

countries.each do |c|
output[:countries] << {
:iso => c.iso,
:name => c.name
}
end
regions.each do |r|
output[:regions] << {
:country => r.country.iso,
:iso => r.iso,
:name => r.name
}
end
cities.each do |c|
output[:cities] << {
:name => c.name,
:country => c.region.country.iso,
:region => c.region.iso,
:lat => c.lat,
:lng => c.lng
}
end

f = File.new('db/geonames.yml', File::CREAT|File::RDWR|File::TRUNC, 0644)
f << output.to_yaml
f.close

if !Airports.nil?
output = {:airports => []}
airports = Airport.find(:all)
airports.each do |a|
output[:airports] << a.attributes
end
f = File.new('db/airports.yml', File::CREAT|File::RDWR|File::TRUNC, 0644)
f << output.to_yaml
f.close
end

Resistor::Geonames.import Resistor::Geonames.import



end end
end end


0 comments on commit 07e5858

Please sign in to comment.