2015-07-25 19:28:32 -05:00
#!/usr/bin/env ruby
2015-08-15 15:36:26 -05:00
require_relative '../lib/wayback_machine_downloader'
2015-08-09 21:26:17 -05:00
require 'optparse'
2015-11-06 13:11:26 -05:00
require 'pp'
2015-08-09 21:26:17 -05:00
options = {}
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: wayback_machine_downloader http://example.com"
opts.separator ""
2015-08-10 01:19:14 -05:00
opts.separator "Download any website from the Wayback Machine."
2015-08-09 21:26:17 -05:00
opts.separator ""
2015-11-06 13:11:26 -05:00
opts.separator "Optional options:"
2015-08-09 21:26:17 -05:00
opts.on("-t", "--timestamp TIMESTAMP", Integer, "Only files on or before timestamp supplied (ie. 20150806225358)") do |t|
options[:timestamp] = t
end
2015-08-22 12:27:19 -05:00
2015-11-06 13:11:26 -05:00
opts.on("--accept-regex [ACCEPT_REGEX]", String,"Specify a regular expression to download. If a path doesn't meet this regex, it won't get downloaded.") do |accept_regex|
options[:accept_regex] = accept_regex
end
2015-08-22 12:27:19 -05:00
opts.on("-v", "--version", "Display version") do |t|
options[:version] = t
end
2015-08-09 21:26:17 -05:00
end.parse!
2015-11-06 13:11:26 -05:00
# this used to be 0. we want to look at the /last/ option.
#
# TODO: this argument needs to be handled better. argument handling is sorta messy.
if base_url = ARGV[-1]
wayback_machine_downloader = WaybackMachineDownloader.new base_url: base_url, timestamp: options[:timestamp], accept_regex: options[:accept_regex]
2015-08-09 21:26:17 -05:00
wayback_machine_downloader.download_files
2015-08-22 12:27:19 -05:00
elsif options[:version]
puts WaybackMachineDownloader::VERSION
2015-08-09 21:26:17 -05:00
else
2015-08-10 01:13:36 -05:00
puts "You need to specify a website to backup. (e.g., http://example.com)"
2015-08-09 21:26:17 -05:00
puts "Run `wayback_machine_downloader --help` for more help."
end