root/ruby/bethefirst3.rb

Revision 228, 1.5 kB (checked in by andrew.pennebak..@gmail.com, 7 months ago)

Added bethefirst3.rb, detection of Firefox 3's release.

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env ruby
2
3 require "open-uri"
4 require "time"
5 require "pp"
6
7 def main
8         puts "Awaiting release."
9
10         while true
11                 t=Time.now
12
13                 puts "Checking mozilla.com #{t.hour}:#{t.min}:#{t.sec}"
14
15                 data=""
16
17                 begin
18                         f=open("http://www.mozilla.com/")
19                         data=f.read
20                         f.close
21                 # Connection error
22                 rescue SocketError=>e
23                         puts "Could not connect. Check network connections."
24                 # HTTP specific error
25                 rescue OpenURI::HTTPError=>e
26                         if e.to_s.include?("503")
27                                 puts "Website unavailable. Possible update in progress."
28                         else
29                                 puts e
30                         end
31                 # Timeout
32                 rescue Errno::ETIMEDOUT=>e
33                         puts "Timeout. Possible update in progress."
34                 # Timeout
35                 rescue Errno::ECONNRESET=>e
36                         puts "Timeout. Possible update in progress."
37                 # Got a web page
38                 else
39                         pp data
40
41                         data.downcase!
42
43                         using_proxy=true
44                         if data.include?("firefox") and data.include?("<a href=\"https://addons.mozilla.org/\">")
45                                 using_proxy=false
46                         end
47
48                         new_firefox_release=false
49                         if (not data.include?("<html><body><b>Http/1.1 Service Unavailable</b></body> </html>")) and (not data.include?("2.0.0.14"))
50                                 new_firefox_release=true
51                         end
52
53                         if using_proxy
54                                 puts "Error: Behind a proxy."
55                         elsif new_firefox_release
56                                 puts "Firefox 3 released!"
57
58 # Roommate annoyed by so many false updates.
59 #                               puts "Sounding alert."
60 #                               system("open favthings.mp3")
61
62                                 puts "Opening announcement page."
63
64                                 system("open http://www.mozilla.com/")
65
66                                 break
67                         # Not released yet; wait 1 second and reload
68                         else
69                                 sleep 1
70                         end
71                 end
72         end
73 end
74
75 if __FILE__==$0
76         begin
77                 main
78         rescue Interrupt=>e
79                 nil
80         end
81 end
Note: See TracBrowser for help on using the browser.