APress Deal of the day

I recently stumbled upon a nice deal on the APress website. They offer a different title as electronic book for $ 10 each day (called ebook deal of the day).

After a couple of days I started to be annoyed by looking on the website every day and wondered how I can make sure that I do not miss something interesting.

I went on and wrote a little ruby script with the cool hpricot library by why the lucky stiff. It runs as a cron job every day and sends an email with the title and description.

In case you are interested, here it is (just edit the smtp_server, sender and receiver variables):

#!/usr/bin/env ruby

require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'net/smtp'

smtp_server = 'your_mail_server'
sender = "your@email_address.here"
receiver = ['receiver1@test.xx', 'receiver2@test.xx']

doc = Hpricot(open("http://www.apress.com/info/dailydeal"))

description = doc.search("//div[@class='bookdetails']")

title = description.search("a").first.inner_html

msg = "Subject: [APress Deal of the Day] #{title}\n\nDeal of the day at APress: #{title}\n\n"

(description/"p").each do |p|
        msg = msg + p.inner_html.gsub(/<\/?[^>]*>/, "") + "\n\n"
end

msg = msg + (description/"div[@class='footer']").inner_html + "\n\n"

msg = msg + "Order at http://www.apress.com/info/dailydeal\n"

Net::SMTP.start(smtp_server) do |smtp|
        smtp.send_message(msg, sender, receiver)
end