Created
July 5, 2013 23:18
-
-
Save davidtrogers/5937804 to your computer and use it in GitHub Desktop.
Search Craigslist SF/Peninsula every 10 seconds for something with `craigslist bmx bike`. `ENV['OPENCL'] = true` opens new urls. defaults to 'table'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'httparty' | |
require 'nokogiri' | |
require 'colorize' | |
require 'uri' | |
query = (ARGV.count > 0 && ARGV.join(' ').dup) || "table" | |
encoded_query = URI.encode query | |
puts ["searching for:".cyan, query.colorize(:red).colorize(background: :white)].join(" ") | |
urls = {}; loop do | |
out = HTTParty.get "http://sfbay.craigslist.org/search/sss/pen?zoomToPosting=&query=#{encoded_query}&srchType=A&minAsk=&maxAsk=" | |
enumerator = Nokogiri.parse(out).css('span.pl a') | |
puts "no links!!!!!".red if enumerator.empty? | |
enumerator.each do |link| | |
if urls.has_key?(link['href']) | |
print '.'.green | |
else | |
url = "http://sfbay.craigslist.com#{link['href']}" | |
`open #{url}` if ENV['OPENCL'] | |
puts link.text.yellow, "\t#{url}".cyan | |
urls[link['href']] = true | |
end | |
end | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment