activerecord-import 0.2.7 + Rails 3.0.7, XML . ( Rails, , ):
require 'open-uri'
artists = Array.new
Artist.establish_connection("http://localhost:3000")
begin
open("*some-url*") do | artists_file |
artists_file.each do | line |
if line =~ /<artist id="([\w_]*)" name="(.*)"[ <]/
puts $1, $2
if line =~ / sort="(.*)"/
puts $1
end
begin
artist = Artist.new(:id => $1, :name => $2)
artists << artist
rescue
puts "Couldn't add " + $1 + ": " + $!
end
end
end
Artist.import artists, :validate => true
end
rescue
puts "Couldn't open the artists file."
end
: nevermind; , AM ID. D'!
share