diff --git a/config/database.yml b/config/database.yml index aa6a16c..fefc9b9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,6 +1,6 @@ development: adapter: sqlite3 - database: db/development.sqlite3 + database: db/development-discogs.sqlite3 pool: 5 timeout: 5000 diff --git a/lib/discogs.rb b/lib/discogs.rb new file mode 100644 index 0000000..7aa41f8 --- /dev/null +++ b/lib/discogs.rb @@ -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 \ No newline at end of file diff --git a/lib/tasks/discogs_import_artists.rake b/lib/tasks/discogs_import_artists.rake new file mode 100644 index 0000000..801e763 --- /dev/null +++ b/lib/tasks/discogs_import_artists.rake @@ -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