examples/cl_watcher.rb in rfuzz-0.7 vs examples/cl_watcher.rb in rfuzz-0.8

- old
+ new

@@ -1,32 +1,35 @@ require 'rubygems' require 'rfuzz/browser' include RFuzz require 'pstore' -if ARGV.length != 4 +if ARGV.length < 4 puts "usage: ruby cl_watcher.rb city cat areaID \"search\"" exit 1 end -city, cat, areaID, search = ARGV[0], ARGV[1], ARGV[2], ARGV[3] +city, cat, areaID, search = ARGV.shift, ARGV.shift, ARGV.shift, ARGV href_seen = PStore.new("watcher_seen_links.pstore") web = Browser.new("#{city}.craigslist.org") loop do puts "Checking..." - web.start("/cgi-bin/search", :query => {"areaID" => areaID, "subAreaID" => "0","query" => search, "catAbbreviation" => cat, "minAsk" => "min", "maxAsk" => "max"}) + search.each do |query| + puts "SEARCH: #{query}" + web.start("/cgi-bin/search", :query => {"areaID" => areaID, "subAreaID" => "0","query" => query, "catAbbreviation" => cat, "minAsk" => "min", "maxAsk" => "max"}) - href_seen.transaction do - web.links(/#{city}.craigslist.org\/#{cat}/).each do |link| - href = link.attributes["href"] - if !href_seen[href] - puts href - puts " -- " + link.children.join + href_seen.transaction do + web.links(/[0-9]*.html/).each do |link| + href = link.attributes["href"] + if !href_seen[href] + puts href + puts " -- " + link.children.join `firefox '#{href}'` href_seen[href] = link + end end end end puts "----\nSleeping..."