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"

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)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>