Page MenuHomePhabricator

mwsearch.rb

Authored By
bzimport
Nov 22 2014, 1:14 AM
Size
1 KB
Referenced Files
None
Subscribers
None

mwsearch.rb

#!/usr/bin/ruby -w
require 'open-uri'
class Search
R_NO_RESULTS = /were no results matching the query/io
# aDelay -- seconds between requests
# aCount -- no. of requests
#
def initialize( aDelay = 1, aCount = 100 )
raise "Bad delay: #{aDelay}" if aDelay < 1 || aDelay > 3600
raise "Bad count: #{aCount}" if aCount < 1 || aCount > 1_000_000
@delay = aDelay
@cnt = aCount
end # initialize
def go # main entry point
# sample queries that fail from tickets: 43544, 42423, 42424, 42426:
q = %w{ https://www.wikidata.org/w/index.php?title=Special%3ASearch&profile=default&search=Boston&fulltext=Search
http://www.mediawiki.org/w/index.php?search=mw.loader.load%28%29&title=Special%3ASearch
http://commons.wikimedia.org/w/index.php?title=Special%3ASearch&profile=advanced&search=Bottle+filling+-incategory%3A%22Bottle_filling%22&fulltext=Search&ns0=1&ns6=1&ns14=1&redirs=1&profile=advanced }
url = q[2]
@cnt.times { |i|
sleep @delay
puts "i = #{i}"
result = open( url ) { |io| io.read }
next if result !~ R_NO_RESULTS
IO.write 'fail.html', result # got failure
puts "Got failure"
break
}
end # go
def self.go( delay, count )
s = Search.new( delay, count )
s.go
end # go
end # Search
if __FILE__ == $0
if ARGV.size == 0
delay, count = 10, 100
elsif ARGV.size == 1
delay = ARGV[0].to_i
count = 100
elsif ARGV.size == 2
delay = ARGV[0].to_i
count = ARGV[1].to_i
else raise "Expected 2 arguments: delay count"
end
Search.go delay, count
end

File Metadata

Mime Type
text/x-ruby
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9762
Default Alt Text
mwsearch.rb (1 KB)

Event Timeline