Skip to content

Instantly share code, notes, and snippets.

@paigeruten
Created January 6, 2013 20:46
Show Gist options
  • Save paigeruten/4470108 to your computer and use it in GitHub Desktop.
Save paigeruten/4470108 to your computer and use it in GitHub Desktop.
take a snapshot of whytheluckystiff.net whenever it updates
begin
require "terminal-notifier"
rescue LoadError
end
require "open-uri"
WHO = "whytheluckystiff.net"
WHAT = "http://"
WHERE = "/"
WHY = WHAT + WHO + WHERE
WHEN = 5*60
loop do
begin
open(WHY) do |why|
content = why.read
latest_why = Dir["why.*.txt"].sort.last
if latest_why.nil? || File.read(latest_why) != content
File.open("why.#{Time.now.strftime '%F.%T'}.txt", "w") { |f| f << content }
TerminalNotifier.notify("#{WHO} has been updated!", title: "Why Daemon", open: WHY) if defined?(TerminalNotifier)
puts "#{Time.now.strftime '%F.%T'}: #{WHO} has been updated!"
end
end
rescue SocketError
puts "#{Time.now.strftime '%F.%T'}: can't reach #{WHO}, retrying in #{WHEN} seconds"
end
sleep(WHEN)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment