Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created February 23, 2012 05:20
Show Gist options
  • Save mark-cooper/1890562 to your computer and use it in GitHub Desktop.
Save mark-cooper/1890562 to your computer and use it in GitHub Desktop.
LibGig jobs RSS to CSV
require 'rss/2.0'
require 'open-uri'
require 'csv'
csv = 'libgig.csv'
source = 'http://publicboard.libgig.com/feeds/rss20'
content = '' # raw content of rss feed will be loaded here
open(source) do |s| content = s.read end
rss = RSS::Parser.parse(content, false)
print "RSS title: ", rss.channel.title, "\n"
print "RSS link: ", rss.channel.link, "\n"
print "RSS description: ", rss.channel.description, "\n"
print "RSS publication date: ", rss.channel.date, "\n"
data = []
rss.items.each do |i|
date = i.date.month.to_s + '/' + i.date.day.to_s + '/' + i.date.year.to_s
job, site, location = i.title.split '/'
city, state = location.split ',' rescue ''
data.push [job, site, city, state, date, i.link]
end
data.each { |f| f.map! { |v| if v.nil? then '' else v.strip end rescue v } }
CSV.open(csv, "wb") do |c|
data.each { |d| c << d }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment