#!/usr/bin/env ruby # checksd.rb: Periodically check Slickdeals RSS feed, and notify when a new post appears # Set this up to run periodically in your crontab # By: Pete Kruckenberg (pete@kruckenberg.com) # # Version: 0.1 September 6, 2005: first deployment # # License and warranty: This program is copyrighted by the author. Permission is granted # to use it for any lawful use. No warranty of usability, implied or otherwise, is made. # Configuration items you will want to change # Where to keep track of Slickdeals URLs we've already seen URLfile = "/home/pete/slickdeals/sdurls.txt" # Where to send an email when we find a new Slickdeal EmailAddr = "5015551212@vtext.com" # What command (including path, arguments) to execute to send notification # Note that EmailAddr must be included in the right place EmailCmd = "/bin/mail -s \"SlickDeal\" #{EmailAddr}" # This should only change if Slickdeals changes their RSS feed URL SlickRSS = "http://www.slickdeals.net/rss.php" # End of configuration items, rest shouldn't need to change # You'll need (besides Ruby) to install RubyGems and the 'simple-rss' gem require 'rubygems' require 'simple-rss' require 'open-uri' # Get the RSS feed rss = SimpleRSS.parse open(SlickRSS) # Initialize a few hashes to track and report on new Slickdeals matches = Hash.new() titles = Hash.new() rss.items.each do |item| matches[item.link] = 0 titles[item.link] = item.title end # This is really ineffecient, but it's good enough for now # Load the URLs from URLfile, and then compare each to each URL in the RSS feed newlines = Array.new() if (File.readable?(URLfile)) file = File.open(URLfile,"r") while file.gets # Get a URL from the URLfile chomp rss.items.each do |item| # Now see if it matches any URLs from the RSS feed if ($_ == item.link) matches[item.link] = 1 # If it does, remember that end end end file.close end # Now, go through all of the RSS feed URLs, and if we find one that didn't match # the URLs in URLfile, that's a new Slickdeal. Notify using EmailCmd, and add the URL # to URLfile mail_open = 0 file = File.new(URLfile,"a+") matches.each do |key, value| if (value == 0) file.puts key + "\n" # Add the URL to URLfile # Only open the mail program once, allows us to send multiple updates in one notice if (mail_open == 0) $mail = IO.popen(EmailCmd,"w") mail_open = 1 end $mail.puts titles[key] + "\n" end end if (mail_open == 1) $mail.close end file.close