Permalink
Browse files

first commit

  • Loading branch information...
1 parent 9918ef9 commit edafd40f0f580f4dd7b3f7bf77b157bbae583b65 @jonmcewen committed Apr 24, 2012
Showing with 64 additions and 0 deletions.
  1. +64 −0 prog.rb
View
64 prog.rb
@@ -0,0 +1,64 @@
+require 'logger'
+require 'net/http'
+
+log = Logger.new(STDOUT)
+log.level = Logger::INFO
+debug = false
+if ARGV.include? '-debug'
+ debug = true
+ log.level = Logger::DEBUG
+ ARGV.shift
+end
+
+print "Enter site names, one per line, then -1 to start processing\n"
+
+# Get sites list from standard input
+
+pages = []
+page = gets.chomp
+until page == "-1"
+ pages << page
+ page = gets.chomp
+end
+
+# Do GETs and find sizes
+log.debug "Getting pages:\n#{pages.join("\n")}\n"
+
+threads = []
+results = []
+
+for page in pages
+ threads << Thread.new(page) { |myPage|
+
+ h = Net::HTTP.new(myPage)
+ if debug
+ h.set_debug_output($stdout)
+ end
+ h.read_timeout = 1.5 # in seconds
+ log.debug "Fetching: #{myPage}"
+ begin
+ resp, data = h.get('/')
+ log.debug "Got #{myPage}: #{resp.message}"
+
+ case resp
+ when Net::HTTPOK
+ log.debug "OK"
+ results << myPage + " " + resp.body.size.to_s
+
+ else
+ log.debug "NOT OK: #{resp}"
+ results << myPage + " *"
+ end
+ rescue => e
+ log.debug e.message
+ results << myPage + " *"
+ end
+ }
+end
+
+
+threads.each { |aThread| aThread.join }
+
+puts "\nResults:\n\n"
+puts results.join("\n")
+puts "-1"

0 comments on commit edafd40

Please sign in to comment.