-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbug
executable file
·71 lines (66 loc) · 1.91 KB
/
bug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/ruby
#
# Batch URL generator
#
# Copyright 2012 Kareem Khazem
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 'optparse'
# Default options
options = {}
options[:base_url] = "http://www.google.co.uk/"
options[:lead_zeroes] = true
options[:start] = 0
options[:end] = 9
# Get command line options
parser = OptionParser.new do |opts|
prog_name = File.basename($PROGRAM_NAME)
opts.banner = <<END_BANNER
Batch URL Generator
```````````````````
Usage: #{prog_name} [options]
END_BANNER
opts.on("-u URL", "--base-url",
"The non-changing part of the URL") do |url|
options[:base_url] = url
end
opts.on("--[no-]lead-zeroes",
"Whether the ID should be padded with 0s") do |lead|
options[:lead_zeroes] = lead
end
opts.on("-s NUM", "--start-id",
"The lowest ID number to generate") do |num|
options[:start] = num.to_i
end
opts.on("-e NUM", "--end-id",
"The highest ID number to generate") do |num|
options[:end] = num.to_i
end
end
parser.parse!
# generate urls
#
# find the length of the id. '-1' means that it will not be padded.
id_length = -1
if options[:lead_zeroes]
high_string = options[:end].to_s
length = high_string.length
end
for i in options[:start] .. options[:end] do
url = sprintf "%s", options[:base_url]
if options[:lead_zeroes]
url += sprintf "%0#{length}d", i
else
url += sprintf "%d", i
end
puts url
end