Scripting for Benefits

What follows is a very short story on how I put my skills to my personal benefits and made my life a titch easier. I hope this turns out to be something that you’ll enjoy taking a quick read through and will amuse you as well.



So, very lately I happened to submit my passport with an embassy for a police clearance certificate that I needed. The embassy was supposed to with hold my passport while they would process my request and I was given a reference number to track my application. As per the embassy it would take 4-6 weeks to process my application. I had to check in into their site with the given reference number and track the status on my request to see if my passport was ready to be picked up or not?

No email notifications, No phone calls, No updates – Nothing. I was left at the mercy of checking in into the application status every day. WTF? Guess what??

Yep! I didn’t had time to check in into a site everyday for the next 4-6 weeks. I was certain I can put that time to a better use. So, I fire up my VIM on one of the VM servers I already have – Churn out a few quick 30 lines of code in 20 minutes and automate the process! And voila! Email notifications, twice a day there you have it!

Here’s the code I used (sensitive details obfuscated obviously):

require 'rubygems'
require 'net/http'
require 'uri'
require 'nokogiri'
require 'mail'
url      = ###/tracktest.php
refnum   = # my application reference number.
passport = # my passport number
uri = URI.parse(url)
response = Net::HTTP.post_form(uri, {"apptype" => "passport", "refno" => refnum, "passport_no" => passport, "submit" => "Submit"})
page = Nokogiri::HTML(response.body)
if response.code == "200"
mail = do
from     '' # don't spam here - email doesn't exist :)
to       ''
subject  'PCC Application Status'
html_part do
content_type 'text/html; charset=UTF-8'
body page.css('table')
mail.delivery_method :sendmail

No rocket science there. Just a simple HTTP form POST that made my life super easy. I had this setup to run twice a day – 8:30am in the morning and 8:30pm in the evening. Here are these nice email updates I used to receive.


I just got this email today and this was my reaction: