Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F10278
mwsearch.rb
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 22 2014, 1:14 AM
2014-11-22 01:14:20 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
mwsearch.rb
View Options
#!/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
Details
Attached
Mime Type
text/x-ruby
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9762
Default Alt Text
mwsearch.rb (1 KB)
Attached To
Mode
T45544: Should return error message (rather than "zero results") when search fails
Attached
Detach File
Event Timeline
Log In to Comment