Forked from brianmichel/last_fm_ruby_weekly_albums.rb
Created
November 11, 2010 13:17
-
-
Save johnmichel/672484 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
require 'rubygems' | |
require 'net/http' | |
require 'rexml/document' | |
include REXML | |
API_KEY = 'KEY GOES HERE' | |
LASTFM_USER = 'USERNAME GOES HERE' | |
user_url = "http://ws.audioscrobbler.com/2.0/?method=user.getweeklyalbumchart&user=#{LASTFM_USER}&api_key=#{API_KEY}" | |
user_xml_data = Net::HTTP.get_response(URI.parse(user_url)).body | |
user_xml_doc = REXML::Document.new(user_xml_data) | |
album_artist = XPath.each(user_xml_doc, "//album/artist/") | |
album_name = XPath.each(user_xml_doc, "//album/name/") | |
puts "This is #{LASTFM_USER}'s weekly chart of top albums!" | |
for k in 0...album_artist.to_a.length | |
puts "Artist: #{album_artist.to_a[k].text} - Album: #{album_name.to_a[k].text}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment