Skip to content

Instantly share code, notes, and snippets.

@matsadler
Created March 19, 2009 18:02
Show Gist options
  • Save matsadler/81977 to your computer and use it in GitHub Desktop.
Save matsadler/81977 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'cgi'
require 'rubygems'
require 'hpricot'
require 'open-uri'
class SXSWPodcast
attr_reader :title, :description, :date, :link
def initialize(title, description, date, link)
@title = title
@description = description
@date = Time.parse( date )
@link = link
end
end
doc = Hpricot( open( "http://sxsw.com/taxonomy/term/44" ) )
nodes = doc.search( ".node" )
podcasts = nodes.map do |node|
title = node.at( "h2.title" ).inner_text.strip
description = node.at( ".content p" ).inner_text.strip
date = node.at( ".submitted .date" ).inner_text.strip
link = node.at( ".content p:last-child a" )[:href]
SXSWPodcast.new(title, description, date, link)
end
require 'rss/maker'
feed = RSS::Rss.new("2.0")
channel = RSS::Rss::Channel.new
channel.title = "SXSW"
channel.link = "http://sxsw.com/taxonomy/term/44"
channel.description = "SXSW podcasts, courtesy of sourcetagsandcodes.com"
podcasts.each do |podcast|
item = RSS::Rss::Channel::Item.new
item.title = podcast.title
item.description = podcast.description
item.link = podcast.link
size = 0 # unknown
type = 'audio/mpeg'
enclosure = RSS::Rss::Channel::Item::Enclosure.new( podcast.link, size, type )
item.enclosure = enclosure
item.date = podcast.date
channel.items << item
end
feed.channel = channel
cgi = CGI.new
puts "Content-type: text/xml"
puts ""
puts feed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment