Skip to content

Instantly share code, notes, and snippets.

@hank
Created August 23, 2009 14:46
Show Gist options
  • Save hank/173318 to your computer and use it in GitHub Desktop.
Save hank/173318 to your computer and use it in GitHub Desktop.
Provides code to generate a feed of classified ads
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'rss/maker'
version = "2.0"
destination = "mdshooters_classifieds.xml"
content = RSS::Maker.make(version) do |m|
m.channel.title = "MDShooters Classifieds RSS"
m.channel.link = "http://www.ralree.info/mdshooters_classifieds.xml"
m.channel.description = "MDShooters Classifieds live so you can snipe."
m.items.do_sort = true
doc = Hpricot(open('http://mdshooters.com/vbclassified.php').read)
(doc/'a').each do |a|
# For every anchor that isn't an image...
if a['href'] =~ /vbclassified.*do=ad/ and not a.inner_html =~ /<img/
i = m.items.new_item
i.title = a.inner_html
i.link = "http://www.mdshooters.com/"+a['href']
i.date = Time.parse((a.parent/'div[@class=time]/span').inner_html.gsub('-', '/')+" 12:00")
i.description = a.parent.parent.inner_html
end
end
end
File.open(destination, "w") do |f|
f.write(content)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment