require 'optparse'
require 'simplecli'
class DomainFinder::Bin
include SimpleCLI
def usage *args
puts <<doco
domain-finder == %{ domain availability utility }
Usage:
domain-finder -h/--help [Not Implemented Yet]
domain-finder -v/--version [Not Implemented Yet]
domain-finder command [options]
Examples:
domain-finder auction
Further help:
domain-finder commands # list all available commands
domain-finder help <COMMAND> # show help for COMMAND
domain-finder help # show this help message
doco
end
def available_help
<<doco
Usage: #{ script_name } available domain.com[ domain2.com]
Summary:
Check the availability of domains (max 500)
doco
end
def available *domains
available_domains = Domain.available? *domains
unless available_domains.empty?
puts "\nAvailable Domains:\n------------------"
available_domains.sort.each do |domain|
puts "- #{domain}"
end
else
puts "No Domains Available"
end
end
def auction_help
<<doco
Usage: #{ script_name } auction
Options:
-d, --dates Set of dates to use in search
-k, --keywords Comma-delimited keywords for domain titles
-p, --pages Number of Google pages to gather domains from
-f, --file Name of a text file to save available domain names to
Examples:
#{ script_name } auction --dates 05-01-2008,06-10-2008..06.15.2008
#{ script_name } auction --keywords seo,blog --dates 06-01-2008..07-01-2008
#{ script_name } auction -f domains.txt --keywords cat,dog -p 2
Summary:
Display available auction domains
doco
end
def auction *args
begin
options = { :dates => [Date.today - 14], :pages => 1 }
opts = OptionParser.new do |opts|
opts.on('-d','--dates DATE'){ |d| options[:dates] = DateRange.parse(d) }
opts.on('-k','--keywords WORDS'){ |w| options[:keywords] = w.split(',') }
opts.on('-p','--pages PAGES'){ |p| options[:pages] = p.to_i }
opts.on('-f','--file FILE'){ |f| options[:file] = f }
end
opts.parse! args
query = %{"Auction Date" #{ options[:dates].join(' OR ') } site:whois.domaintools.com }
query += options[:keywords].map { |k| "intitle:#{k}" }.join(' OR ') if options[:keywords]
puts "Searching google ... [#{query}]"
results = Google.search(query, :pages => options[:pages] )
print "Getting domains ."
auction_domains = results.inject([]) do |all,result|
if result.cached
print '.'
all + DomainTools.auction_domains( open(result.cached) )
else
all # no google cache for this result, continue on to the next result
end
end
print "\n"
puts "Checking availability of #{ auction_domains.length } domains ..."
available_domains = Domain.available? *auction_domains
unless available_domains.empty?
puts "\nAvailable Domains:\n------------------"
available_domains.sort.each do |domain|
puts "- #{domain}"
end
File.open(options[:file],'w'){|f| f << available_domains.sort.join("\n") } if options[:file]
else
puts "No Domains Available"
end
rescue => ex
puts "Exception: #{ex.inspect}"
end
end
end