Created
September 2, 2010 01:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/pkg/bin/ruby | |
require 'rss' | |
require 'uri' | |
require 'open-uri' | |
class RSS_Merge | |
def initialize(url_arr) | |
@contents = load(url_arr) | |
end | |
def load(url_arr) | |
url_arr.map do |uri| | |
parse(open(URI.encode(uri))) | |
end | |
end | |
def parse(content) | |
RSS::Parser::parse(content) | |
rescue RSS::InvalidRSSError | |
RSS::Parser::parse(content, false) | |
end | |
def merge_rss | |
RSS::Maker.make("2.0") do |maker| | |
maker.channel.about = "udonchan's rss" | |
maker.channel.title = "udonchan" | |
maker.channel.description = "udonchan's rss" | |
maker.channel.link = 'http://udonchan.org/~udonchan/' | |
maker.items.do_sort = true | |
@contents.each do |c| | |
c.items.each do |i| | |
i.setup_maker(maker) | |
end | |
end | |
end | |
end | |
end | |
print "Content-type: application/xml\n" | |
print "Pragma: no-cache\n" | |
print "Cache-Control: no-cache\n" | |
print "Expires: #{Time.now} \n\n" | |
puts RSS_Merge.new(['http://d.hatena.ne.jp/UDONCHAN/rss2', | |
'http://roadbike.g.hatena.ne.jp/UDONCHAN/rss2', | |
'http://gist.github.com/udonchan.atom']).merge_rss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment