Skip to content

Instantly share code, notes, and snippets.

@phillmv
Created March 24, 2011 01:28
Show Gist options
  • Save phillmv/884394 to your computer and use it in GitHub Desktop.
Save phillmv/884394 to your computer and use it in GitHub Desktop.
Craiglist doesn't allow negative keyword searches. I fixed that.
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
bad_words = ["basement", "realtor", "finch", "eglinton", "scarborough", "brampton", "sheppard", "kipling", "islington", "markham", "lawrence", "steeles", "pape", "donlands", "etobicoke", "mississauga", "highway", "cityplace", "yonge", "mortgage", "consultation"]
search_url = "http://toronto.en.craigslist.ca/search/apa?query=&srchType=A&minAsk=&maxAsk=1000&bedrooms=&format=rss"
doc = Nokogiri::XML(open(search_url))
# unnecessary for greader to pick it up
doc.css("items").remove
doc.css("item").each do |entry|
text = entry.to_s.downcase
bad_words.each do |word|
if !text.index(word).nil?
entry.remove
break
end
end
end
File.open("out.rss", "w") do |io| io.puts doc.to_xml end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment