Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Last active February 9, 2017 04:38
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jfahrenkrug/817585 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/817585 to your computer and use it in GitHub Desktop.
Ruby Script to check whether WWDC 2013 has been announced.
# in 2013 by Johannes Fahrenkrug, http://springenwerk.com
# See you at WWDC!
require 'rubygems'
require 'open-uri'
class WWDC2013
def self.announced?
begin
indicator_line = open('https://developer.apple.com/wwdc/') do |f|
f.detect { |line| line =~ /wwdc2012-june-11-15.jpg/ }
end
rescue Exception => e
#system("say -v \"Bad News\" \"Error: #{e.message}\"")
print "Error: #{e.message}\n"
end
indicator_line == nil
end
def self.speak
line = "Rejoice, all you people: WWDC 2013 has been announced!"
if defined? NSSpeechSynthesizer
ns = NSSpeechSynthesizer.new
ns.voice = "com.apple.speech.synthesis.voice.GoodNews"
ns.startSpeakingString(line)
else
system("say -v \"Good News\" \"#{line}\"")
end
end
end
if defined? NSObject
begin
# for OSX 10.8
framework 'CoreGraphics'
rescue
end
require 'hotcocoa'
class Application
include HotCocoa
def start
@firstrun = true
application(:name => "WWDC 2013") do |app|
app.delegate = self
window(:frame => [100, 100, 300, 200], :title => "WWDC 2013 - springenwerk.com", :background_color => color(:name => :black)) do |win|
win << result_field
win << last_checked_field
win << label(:text => "Has WWDC 2013 been announced yet?", :text_color => color(:name => :white))
win.will_close { exit }
end
start_polling(0.5, false)
end
end
private
def start_polling(seconds = 10, should_repeat = true)
# so MRI doesn't complain
eval("NSTimer.scheduledTimerWithTimeInterval(seconds, target:self, selector:'update:', userInfo:nil, repeats:should_repeat)")
end
def result_field
@result_field ||= label(:text => "Nope.", :font => font(:name => "Tahoma", :size => 90), :text_color => color(:name => :red), :text_align => :left)
end
def last_checked_field
@last_checkd_field ||= label(:text => "Checking... ", :font => font(:name => "Tahoma", :size => 10), :text_color => color(:name => :gray), :text_align => :left)
end
def update(timer = nil)
timestr = Time.now.localtime.strftime("at %I:%M:%S%p")
if WWDC2013.announced?
timer.invalidate if timer
result_field.text = 'YES!'
result_field.textColor = color(:name => :green)
last_checked_field.text = timestr
WWDC2013.speak
else
result_field.text = 'Nope.'
result_field.textColor = color(:name => :red)
last_checked_field.text = timestr
if @firstrun
@firstrun = false
timer.invalidate if timer
start_polling
end
end
end
end
Application.new.start
else
while true
print Time.now.localtime.strftime("At %I:%M:%S%p WWDC 2013 has...")
if WWDC2013.announced?
print " BEEN ANNOUNCED!!!\n"
WWDC2013.speak
break
else
print " not been announced yet :(\n"
end
sleep 10
end
end
@jfahrenkrug
Copy link
Author

Hi @spyrnmr, thank you for your feedback! I noticed that too and recently changed the announced? method to handle exceptions. In my experience that covers the 404 problem. Or does it still occur?

@bobspryn
Copy link

bobspryn commented Apr 8, 2012

Ah. Nope that should do it. Wasn't actually using your script, just my own bash script. Was curious what others had built. Didn't realize your exception captured 404's. See you there!

@jfahrenkrug
Copy link
Author

Haha, yeah, let's hope our scripts help us to get a ticket :)

@sebastato
Copy link

Thanks, @jfahrenkrug. Really nice. Hopefully see you in SFO.

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