1
0
Fork 0

Discogs config and task

This commit is contained in:
magnolia-fan 2011-09-21 10:40:04 +04:00
parent 5145320509
commit 5798955b01
3 changed files with 38 additions and 1 deletions

View File

@ -1,6 +1,6 @@
development:
adapter: sqlite3
database: db/development.sqlite3
database: db/development-discogs.sqlite3
pool: 5
timeout: 5000

28
lib/discogs.rb Normal file
View File

@ -0,0 +1,28 @@
class Discogs
def self.artists
File.open('tmp/data/discogs_artists.xml') do |file|
Nokogiri::XML::Reader.from_io(file).each do |node|
if node.name == 'artist' and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
self.process_artist Nokogiri::XML(node.outer_xml).root
end
end
end
end
def self.process_artist node
Artist.new(
:name => (node.css('name').first.text),
:pic_url => (node.css('images > image[type="primary"]').first.text unless node.css('images > image[type="primary"]').empty?),
:status => 1
).save
p node.css('name').first.text
end
def self.releases
end
def self.process_release
end
end

View File

@ -0,0 +1,9 @@
require "discogs"
namespace :discogs do
namespace :import do
desc 'Import discogs artist xml'
task :artists => :environment do
Discogs.artists
end
end
end