Skip to content

Instantly share code, notes, and snippets.

@skord
Created May 23, 2012 13:14
Show Gist options
  • Select an option

  • Save skord/2775178 to your computer and use it in GitHub Desktop.

Select an option

Save skord/2775178 to your computer and use it in GitHub Desktop.
wootlet
#!/usr/bin/env ruby
require 'rubygems'
require 'feedzirra'
require 'open-uri'
def item_prices(parsed_feed, number_to_display)
prices = parsed_feed.entries[1..number_to_display].collect {|x| x.summary.scan(/itemPrice:\'(\d{1,}\.\d{2})/)}.collect {|x| x.flatten}
prices.collect {|x| if x.empty?; x= 'N/A'; else x = x[0].to_f; end}
end
def item_titles(parsed_feed, number_to_display)
parsed_feed.entries[1..number_to_display].collect {|x| x.title}
end
def feed_title(parsed_feed)
parsed_feed.title
end
def feed_url(parsed_feed)
parsed_feed.url
end
feed = Feedzirra::Feed.fetch_and_parse('http://www.woot.com/blog/rss.aspx')
puts item_titles(feed, 5) if ARGV.include?('--titles')
puts item_prices(feed, 5) if ARGV.include?('--prices')
puts feed_title(feed) if ARGV.include?('--title')
puts feed_url(feed) if ARGV.include?('--url')
if ARGV.length == 0
puts 'no valid arguments. choose --titles, --prices, --title (for feed title) or --url (for feed URL)'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment