Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created July 13, 2009 21:02
Show Gist options
  • Save dmerrick/146453 to your computer and use it in GitHub Desktop.
Save dmerrick/146453 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
# grab goove salad playlist from twitter
# (avoids using Soma.fm to keep costs low)
require 'rss/2.0'
require 'open-uri'
# thank you http://rubyrss.com!
# the groovesalad twitter feed
source = "http://twitter.com/statuses/user_timeline/6681342.rss"
# the number to of songs and columns to show
number = ARGV.shift.to_i || 3
truncate = ARGV.shift.to_i || 80
# read the feed
rss = RSS::Parser.parse(open(source).read, false)
songs = rss.items[0..number-1].map {|tweet| tweet.title.sub(/^.*♫ /,'') }
def justify_on_dash(song_list, spacer = " ")
song_list.map!{|song| song.to_s.split(/ - /) }
song_length = song_list.inject(""){|longest,current| longest.length > current.last.length ? longest : current.last }.size
artist_length = song_list.inject(""){|longest,current| longest.length > current.first.length ? longest : current.first }.size
song_list.map{|artist,song| "#{artist.rjust(artist_length, spacer)} - #{song.ljust(song_length, spacer)}"}
end
justify_on_dash(songs).each {|track| puts track[0..truncate-1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment