Created
February 24, 2010 18:17
-
-
Save spiceee/313681 to your computer and use it in GitHub Desktop.
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
namespace :open_directory do | |
# http://www.google.com/Top/ | |
# http://rdf.dmoz.org/rdf/structure.rdf.u8.gz | |
desc "tasks that deal with Google Open Directory importing" | |
task :import => :environment do | |
seeds = [] | |
Category.delete_all | |
File.open(RAILS_ROOT + "/assets/structure.rdf.u8").grep(/<Topic r:id="Top\/Business\//) do |ln| | |
parts = ln.sub(/<Topic r:id=\"Top\/Business\/([^>]+)">$/, '\1').gsub('_', " ").split('/').collect(&:strip) | |
parent_id = nil | |
parts.each do |part| | |
unless (categ = Category.find(:first, :conditions => {:name => part, :parent_id => parent_id})) | |
categ = Category.create!(:name => part, :parent_id => parent_id) | |
puts "new category: #{part} - father: #{categ.parent.andand.name}" | |
seeds.push "Category.create(:name => \"#{part}\", :parent_id => #{parent_id.nil? ? 'nil' : parent_id})" | |
end | |
parent_id = categ.id | |
end | |
end | |
open(RAILS_ROOT + "/db/seeds.rb","a").write seeds.join("\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment