Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created August 10, 2011 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxmph/1137462 to your computer and use it in GitHub Desktop.
Save pdxmph/1137462 to your computer and use it in GitHub Desktop.
Combine a pair of RSS feeds
#!/usr/bin/env ruby
require "rubygems"
require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'
require 'rss/maker'
version = "2.0"
dest_dir = ""
destination = "#{dest_dir}/smt_combined_nl_rss.xml"
# http://socialmediatoday.com/feeds/nl/smt_curators_picks.xml
# http://socialmediatoday.com/feeds/nl/smt_popular_posts.xml
root_url = "http://socialmediatoday.com/feeds/nl"
feeds = ["/smt_curators_picks.xml", "/smt_popular_posts.xml"]
rss_items = []
feeds.each do |f|
source = "#{root_url}#{f}"
content = ""
open(source) do |s|
content += s.read
end
rss = RSS::Parser.parse(content, false)
rss.items.each do |i|
rss_items << i
end
end
rss_output = RSS::Maker.make(version) do |m|
m.channel.title = "SMT Combined Picks/Popular Feed"
m.channel.link = "http://socialmediatoday.com"
m.channel.description = "Combined RSS feed for editor\'s picks and popular items"
m.items.do_sort = true
rss_items.each do |i|
begin
item = m.items.new_item
item.title = i.title
item.link = i.link
item.date = i.date
item.description = i.description
item.dc_creator = i.dc_creator
item.author = i.dc_creator
item.guid.content = i.guid
item.guid.content = i.guid.to_s
rescue
end
end
end
File.open(destination, "w") do |f|
f.write(rss_output)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment