Skip to content

Instantly share code, notes, and snippets.

@curious-attempt-bunny
Created February 19, 2012 21:46
Show Gist options
  • Save curious-attempt-bunny/1866007 to your computer and use it in GitHub Desktop.
Save curious-attempt-bunny/1866007 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'curb'
require 'json'
host = 'techlandia.herokuapp.com'
# host = 'localhost:3000'
url = "http://#{host}/posts.json"
cdataRegex = /<!\[CDATA\[(.*)\]\]>/m
feeds = ['http://portland.craigslist.org/sof/index.rss', 'http://portland.craigslist.org/eng/index.rss']
feeds.each do |feed|
doc = Hpricot.parse(open(feed))
(doc/:item).each do |xml_product|
post = {}
post['title'] = xml_product.search("/title").inner_text
post['url'] = xml_product.%('dc:source').inner_text
post['content'] = xml_product.search("/description").inner_html
post['posted'] = xml_product.%('dc:date').inner_text
m = cdataRegex.match post['content']
post['content'] = m[1] if m and m[1]
post['content'] = post['content'].scan(/[[:print:]]/).join
puts post['title']
Curl::Easy.http_post(url, post.to_json()
) do |curl|
curl.headers['Content-Type'] = 'application/json'
end
# break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment