Skip to content

Instantly share code, notes, and snippets.

@johnd
Created January 10, 2010 01:00
Show Gist options
  • Save johnd/273253 to your computer and use it in GitHub Desktop.
Save johnd/273253 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'nokogiri'
gem 'twitter'
require 'twitter'
TWITTER_USERNAME = 'NorthernRockSVR'
TWITTER_PASSWORD = 'password'
LAST_FILE = File.expand_path(File.dirname(__FILE__)) + "/last_svr"
url = "http://www.northernrockassetmanagement.co.uk/mortgages/existing_customers/standard_variable_rate/"
doc = Nokogiri::HTML(open(url))
svr = doc.at_css("#iMain ul:nth-child(2) li:nth-child(1)").text[/[0-9\.]+\%/]
if File.exists?(LAST_FILE)
file = File.new(LAST_FILE, 'r')
last_svr = file.gets
else
last_svr = "NO FILE"
end
unless svr == last_svr.strip
httpauth = Twitter::HTTPAuth.new(TWITTER_USERNAME, TWITTER_PASSWORD)
client = Twitter::Base.new(httpauth)
client.update("Northern Rock Asset Management SVR is now #{svr}.")
write_svr = File.new(LAST_FILE, 'w+')
write_svr.puts svr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment