Created
January 6, 2013 20:46
-
-
Save paigeruten/4470108 to your computer and use it in GitHub Desktop.
take a snapshot of whytheluckystiff.net whenever it updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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