Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created June 18, 2010 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttscoff/442985 to your computer and use it in GitHub Desktop.
Save ttscoff/442985 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -rjcode -Ku
require 'rss/2.0'
require 'open-uri'
require 'time'
class RSSFetcher
RED = "\033[1;31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
WHITE = "\033[37m"
DKGRAY="\033[0;30m"
GRAY="\033[0;37m"
DEFAULT="\033[0;39m"
def parseFeed (url,length)
res = nil
open(url) do |http|
response = http.read
res = RSS::Parser.parse(response, false)
end
output = "#{GRAY}#{res.channel.title}\n"
res.items.each_with_index {|item, i|
if i < length.to_i
pd = Time.parse("#{item.pubDate}")
t = Time.now.strftime("%a") == pd.strftime("%a") ? GREEN : BLUE
t += pd.strftime("%a %I:%M%p").gsub(/0(\d):/," \\1:").gsub /([AP]M)/ do
|w| w.downcase
end
output += "#{t} #{GRAY}#{item.title}\n"
else
break
end
}
return output
end
end
url = ARGV[0] ? ARGV[0] : "http://www.tuaw.com/rss.xml"
limit = ARGV[1] ? ARGV[1] : 10
print RSSFetcher.new.parseFeed(url,limit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment