Get outstanding balancedetails emailed from Digital Ocean

I recently looked at Digital Ocean as a possible replacement VM host as a company project and have now chosen to use them for my own personal VM. Since I am using a prepaid option the need to get some warning when my prepaid amount was due to run out became a requirement. Below is the Ruby code I use to pull the remaining credit and email on a daily basis. Hope you find it useful. I run this daily via a cron entry. The requirements are Ruby 1.9+ (I am sure it will work on lower but only tested on 1.9+) and the mechanize Ruby gem.

#!/usr/bin/ruby

require 'mechanize'
require 'net/smtp'

user = 'your_username_here'
pass = 'your_password_here'

# login
agent = Mechanize.new { |a|
a.follow_meta_refresh = true
}
agent.get("https://cloud.digitalocean.com/login")
form = agent.page.forms[0]
form["user[email]"] = user
form["user[password]"] = pass
form.submit

# get balance
billing_page = agent.get("https://cloud.digitalocean.com/billing")
balance = (billing_page.body.scan(/\$\d*\.\d*/).first.scan(/\d*\.\d*/).first).to_f

# email results
subject = "Digital Ocean billing checker - #{DateTime.now.ctime.to_s}"
subject = "WARNING - " + subject if balance < 1.00
message = <<MESSAGE_END
From: Digital Ocean billing checker <your_email_address_here>
To: your_email_address_here
Subject: #{subject}

The current credit is : $#{balance.to_s}
MESSAGE_END
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, 'your_email_address_here', 'your_email_address_here'
end