Path: blob/master/lib/anemone/cli/serialize.rb
19534 views
require 'anemone'1require 'optparse'2require 'ostruct'34begin5# make sure that the first option is a URL we can crawl6root = URI(ARGV[0])7rescue8puts <<-INFO9Usage:10anemone serialize [options] <url>1112Synopsis:13Crawls a site starting at the given URL and saves the resulting14PageStore object to a file using Marshal serialization.1516Options:17-o, --output filename Filename to save PageStore to. Defaults to crawl.{Time.now}18INFO19exit(0)20end2122options = OpenStruct.new23options.output_file = "crawl.#{Time.now.to_i}"2425# parse command-line options26opts = OptionParser.new27opts.on('-o', '--output filename') {|o| options.output_file = o }28opts.parse!(ARGV)2930Anemone.crawl(root) do |anemone|31anemone.after_crawl do |pages|32open(options.output_file, 'w') {|f| Marshal.dump(pages, f)}33end34end353637