-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
21 lines (18 loc) · 870 Bytes
/
main.rb
File metadata and controls
21 lines (18 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'optparse'
require_relative 'crawlable_pages'
require_relative 'crawler'
options = {:prod => false}
OptionParser.new do |opt|
opt.on('-i', '--input_file INPUT_FILE', 'Input filename in ./crawlables/ [required]') { |o| options[:input_file] = o }
opt.on('-l', '--limit LIMIT', 'Crawling limit [required]') { |o| options[:limit] = Integer(o) }
opt.on('-u', '--url URL', 'Alternative starting URL') { |o| options[:url] = o }
opt.on('--prod', 'Production environment, development if not set') { |o| options[:prod] = o }
end.parse!
# raise an exception if the required arguments are not set
raise OptionParser::MissingArgument if options[:input_file].nil?
raise OptionParser::MissingArgument if options[:limit].nil?
Crawler.new(
CrawlablePages.new(options[:input_file], options[:url]).get_crawlable,
options[:limit],
options[:prod]
).start_crawling()