Skip to content

Instantly share code, notes, and snippets.

@electronicbites
Created March 11, 2009 22:48
Show Gist options
  • Save electronicbites/77803 to your computer and use it in GitHub Desktop.
Save electronicbites/77803 to your computer and use it in GitHub Desktop.
get similar artists from the last.fm api
#http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=cher&api_key=b25b959554ed76058ac220b7b2e0a026
require 'rubygems'
require 'hpricot'
require 'net/http'
HOST = "ws.audioscrobbler.com"
SITE = "/2.0"
def get_similar_artists(artist)
request = Net::HTTP::Get.new("#{SITE}?method=artist.getsimilar&artist=#{artist}&api_key=b25b959554ed76058ac220b7b2e0a026")
Net::HTTP.start("#{HOST}", 80) do |http|
(Hpricot(http.request(request).body)/'artist').collect do |artist|
(artist/'name').inner_html rescue nil
end
end
end
get_similar_artists('cher')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment