Finally fixed lastfm post requests, couple of rake tasks

This commit is contained in:
magnolia-fan
2011-09-18 18:25:47 +04:00
parent d9b75279f5
commit e69a12ded5
7 changed files with 60 additions and 20 deletions
+22
View File
@@ -0,0 +1,22 @@
namespace :db do
namespace :artist do
desc 'Fix broken imports'
task :fix => :environment do
Artist.where(:status => [0, 2]).each do |artist|
artist.albums.each do |album|
album.destroy
end
puts artist.name+(artist.mbid.nil? or artist.mbid.empty? ? '' : ' ('+artist.mbid+')')
res = ImportController.importArtist(artist.name)
if res == 1
puts 'OK'
elsif res == 2
puts 'FAIL'
elsif res == 3
puts 'SKIP'
end
puts ''
end
end
end
end
+17
View File
@@ -18,5 +18,22 @@ namespace :lastfm do
puts ''
end
end
task :hyped => :environment do
ImportController.parseLastfmXML('tmp/data/hyped500.xml').each do |artist|
puts artist[:name] + (artist[:mbid].empty? ? '' : ' (' + artist[:mbid] + ')')
record = Artist.find_or_create_by_name(artist[:name])
record.mbid = artist[:mbid]
record.save
res = ImportController.importArtist(artist[:name])
if res == 1
puts 'OK'
elsif res == 2
puts 'FAIL'
elsif res == 3
puts 'SKIP'
end
puts ''
end
end
end
end