Created
June 22, 2017 18:19
-
-
Save FennyFatal/71d5bf97843850429b58c02a513c8df5 to your computer and use it in GitHub Desktop.
Crappy LFM taste-o-meter
This file contains 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
def get_lfm_artist_gids(a_user) | |
response = Net::HTTP.get_response("ws.audioscrobbler.com", "/2.0/?method=user.gettopartists&user=#{get_user(a_user)}&limit=1&api_key=#{$api_key}&format=json") | |
jresponse = JSON.parse(response.body) | |
puts jresponse.inspect | |
page = 1 | |
gids = [] | |
until page > jresponse['topartists']['@attr']['totalPages'].to_i do | |
response = Net::HTTP.get_response("ws.audioscrobbler.com", "/2.0/?method=user.gettopartists&user=#{get_user(a_user)}&limit=1000&page=#{page}&api_key=#{$api_key}&format=json") | |
jresponse = JSON.parse(response.body) | |
jresponse['topartists']['artist'].each do |artist| | |
gids << { :gid => artist['mbid'] , :name => artist['name']} | |
end | |
page = page + 1 | |
end | |
gids | |
end | |
def do_compare_gids(a_user,another_user) | |
a_user_gids = get_lfm_artist_gids(a_user) | |
another_user_gids = get_lfm_artist_gids(another_user) | |
max = a_user_gids.count < another_user_gids.count ? a_user_gids.count : another_user_gids.count | |
result = a_user_gids & another_user_gids | |
"#{a_user} and #{another_user} are #{"%3.2f" % (result.count.to_f * 100 / max) }% compatible.\n" + | |
"Top artists: #{result[0..4].map{|a| "#{a[:name]}"}.join(', ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment