Discogs config and task
This commit is contained in:
parent
5145320509
commit
5798955b01
|
@ -1,6 +1,6 @@
|
|||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
database: db/development-discogs.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue