Skip to content

Instantly share code, notes, and snippets.

@ntalbott
Created March 19, 2014 14:18
Show Gist options
  • Save ntalbott/9642553 to your computer and use it in GitHub Desktop.
Save ntalbott/9642553 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'uri'
require 'rss/1.0'
require 'rss/2.0'
class Time
def distance_ago_in_words
seconds = (Time.now - self).to_i
minutes = seconds / 60
hours = ( seconds / 3600 )
days = ( seconds / 86400 )
if days > 0
"#{days} days ago"
elsif hours > 0
"#{hours} hours ago"
elsif minutes > 0
"#{minutes} minutes ago"
else
"now"
end
end
end
url = "http://ws.audioscrobbler.com/1.0/user/#{ENV['USER']}/recenttracks.rss"
rss = RSS::Parser.parse(open(url) {|r| r.read }, false)
last_items = [10, rss.items.size].min
last_items.times do |i| item = rss.items.reverse[i]
puts "#{item.title} (#{item.date.distance_ago_in_words})"
end
ntalbott@lorica:~/tmp$ USER=jmoses ruby lfm.rb
The Civil Wars – The One That Got Away (142 days ago)
The Civil Wars – I Had Me a Girl (142 days ago)
Goo Goo Dolls – Rebel Beat (77 days ago)
Goo Goo Dolls – When the World Breaks Your Heart (77 days ago)
Balkan Beat Box – Part of the Glory (52 days ago)
Balkan Beat Box – Political Fuck (52 days ago)
Shazalakazoo – Opla (52 days ago)
Shazalakazoo feat. Hornsman Coyote & St.Sevqet – Ava Kari (52 days ago)
De La Soul – Intro (31 days ago)
De La Soul – Bionix (31 days ago)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment