Skip to content

Instantly share code, notes, and snippets.

@auxesis
Created January 9, 2011 13:38
Show Gist options
  • Select an option

  • Save auxesis/771687 to your computer and use it in GitHub Desktop.

Select an option

Save auxesis/771687 to your computer and use it in GitHub Desktop.
Quick and dirty hack to clean out Last.fm track profile one page at a time.
#!/usr/bin/env ruby
require 'rubygems'
require 'webrat'
require 'rspec'
require 'nokogiri'
Webrat.configure do |config|
config.mode = :mechanize
end
include Webrat::Matchers, Webrat::Methods
visit 'https://last.fm/login'
fill_in 'username', :with => 'foo'
fill_in 'password', :with => 'bar'
click_button 'Come on in'
visit 'http://www.last.fm/user/foo/tracks'
response_body.should =~ /Logout/
formtoken = response_body[/formtoken":"(\w+)",/, 1]
last = response_body[/var lastrt = (\d+);/, 1]
doc = Nokogiri::HTML(response_body)
doc.search('a.delete').each do |element|
element.attributes['onclick'].to_s.split(';').last.split(';').last.match(/(\d+), (\d+)/)
track = $1
date = $2
row_id = element.parent.parent.attributes['id'].to_s
data = { '_' => '', 'mc' => '1', 'rowid' => row_id,
'track' => track, 'date' => date,
'formtoken' => formtoken, 'last' => last }
p data
visit 'http://www.last.fm/ajax/rmrecenttrack', :post, data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment