Skip to content

Instantly share code, notes, and snippets.

@botanicus
Created December 19, 2011 23:26
Show Gist options
  • Select an option

  • Save botanicus/1499404 to your computer and use it in GitHub Desktop.

Select an option

Save botanicus/1499404 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: utf-8
require "open-uri"
require "nokogiri"
# Configuration.
URL = "http://www.xe.com/ucc/convert/?Amount=1&From=GBP&To=%s"
EMAIL = "[email protected]"
NOTIFY_IF = {CZK: 30, EUR: 1.19}
CURRENCIES = NOTIFY_IF.keys
# Helpers.
def notify(email, currency, rate)
system("echo '' | mail #{email} -s '1 #{currency} is #{rate} today!'")
end
# Main.
CURRENCIES.each do |currency|
open(URL % currency) do |stream|
document = Nokogiri::HTML(stream.read)
data = document.css("table.Cnvrsn tr.CnvrsnTxt").inner_text.gsub(/\s+/m, " ")
data.match(/1.00 GBP = ([\d\.]+)/) do |match|
rate = match[1].to_f
puts "~ 1 #{currency} is #{rate} today."
notify(EMAIL, currency, rate) if rate > NOTIFY_IF[currency]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment