Loading external data
Using ActiveRecord outside rails. Easy-peasy.
Here's the result. Ignoring the first couple of runs that failed due to typos, I was pleased to see it fail due to the lack of a categories table. Rake fixed that.
Edison:~/Desktop/ebay $ ruby ebay_loader.rb ------ 37
And the code itself:
#!/usr/local/bin/ruby
#
require 'yaml'
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:database => "box_auction_808_dev",
:username => "root",
:password => "")
class Category < ActiveRecord::Base
end
categories = YAML::load( File.open('ebay_categories.yml', 'r') )
categories["categories"].each do |k,v|
@c = Category.new
@c.name = k
@c.save!
end
puts "------"
@allc = Category.all
puts @allc.length
Finally, the categories which I shamelessly copied from ebay:
categories: Antiques: Art: Baby: Books: Business & Industrial: ...
Comments