Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save botanicus/1065532 to your computer and use it in GitHub Desktop.
exchange-rates.rb
#!/usr/bin/env ruby
# encoding: utf-8
require "open-uri"
# Configuration.
URL = "http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt"
EMAIL = "stastny@101ideas.cz"
# Helpers.
def notify(email, rate)
system("mail #{email} -s '1 GBP is #{rate} today!'")
end
# Main.
open(URL) do |stream|
stream.read.match(/GBP\|(\d+),(\d+)/) do |match|
rate = "#{match[1]}.#{match[2]}".to_f
puts "~ 1 GBP is #{rate} today."
notify(EMAIL, rate) if rate > 27
end
end
@botanicus
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment