Created
September 13, 2012 04:09
-
-
Save daz/3711799 to your computer and use it in GitHub Desktop.
Watch for Apple event video posting
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
#!/usr/bin/ruby | |
# encoding: utf-8 | |
# Pings Apple events page until the video is posted | |
# Videos are usually live ~6 hours after official start time | |
# | |
# $ git clone https://gist.github.com/3711799.git appleevent | |
# $ ruby appleevent/appleevent.rb | |
require 'date' | |
require 'net/http' | |
url = "http://www.apple.com/apple-events/#{Date::MONTHNAMES[Date.today.month].downcase}-#{Date.today.year}/" | |
uri = URI(url) | |
STDOUT.sync = true | |
puts "Checking #{url}" | |
redirect_script = %[<script type="text/javascript" charset="utf-8">location.href="/apple-events/"</script>] | |
1000.times do | |
result = Net::HTTP.get_response(uri) | |
if result.code.to_i == 200 && result.body !=~ /http-equiv="refresh"/ && result.body.strip != redirect_script | |
print "😄\n" | |
%x(open -a Safari #{url}) | |
break | |
else | |
print '.' | |
sleep 30 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment