Permalink
Browse files

No commit message

  • Loading branch information...
1 parent 8af7cd8 commit 07e585899b8707540053632163ee2713231d125f christocracy committed May 9, 2008
Showing with 60 additions and 0 deletions.
  1. +3 −0 lib/geonames.rb
  2. +57 −0 tasks/geonames_tasks.rake
View
@@ -183,3 +183,6 @@ def self.import_cities15000
end
end
end
+
+
+
View
@@ -11,8 +11,65 @@ namespace :geonames do
puts " Importing geonames "
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
+
end
end

0 comments on commit 07e5858

Please sign in to comment.