summaryrefslogtreecommitdiff
path: root/sample/rss
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 08:47:28 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 08:47:28 +0000
commit2572d5e20efb42599759f97b1ec0cc66c15fb14a (patch)
tree1ce8b2aa09c9351b5e1efae7981c80d1bc916d85 /sample/rss
parent0a93165e167a4d1d6b0f8a2dc0479524f49855d4 (diff)
* lib/rss/{0.9,1.0,2.0,trackback,xml-stylesheet}.rb: added
#setup_maker. * test/rss/test_setup_maker_*.rb: added tests for #setup_maker. * lib/rss/maker/base.rb(RSS::Maker::Items#max_size=): supported output item size limitation. * sample/rss/blend.rb: added sample for RSS Maker. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/rss')
-rwxr-xr-xsample/rss/blend.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/sample/rss/blend.rb b/sample/rss/blend.rb
new file mode 100755
index 0000000..2aa30d7
--- /dev/null
+++ b/sample/rss/blend.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env ruby
+
+require "rss/1.0"
+require "rss/2.0"
+require "rss/dublincore"
+require "rss/maker"
+
+feeds = []
+verbose = false
+encoding = "UTF-8"
+
+def error(exception)
+ mark = "=" * 20
+ mark = "#{mark} error #{mark}"
+ STDERR.puts mark
+ STDERR.puts exception.class
+ STDERR.puts exception.message
+ STDERR.puts exception.backtrace
+ STDERR.puts mark
+end
+
+before_time = Time.now
+ARGV.each do |fname|
+ if fname == '-v'
+ verbose = true
+ next
+ end
+ rss = nil
+ f = File.new(fname).read
+ begin
+ ## do validate parse
+ rss = RSS::Parser.parse(f)
+ rescue RSS::InvalidRSSError
+ error($!) if verbose
+ ## do non validate parse for invalid RSS 1.0
+ begin
+ rss = RSS::Parser.parse(f, false)
+ rescue RSS::Error
+ ## invalid RSS.
+ error($!) if verbose
+ end
+ rescue RSS::Error
+ error($!) if verbose
+ end
+ if rss.nil?
+ STDERR.puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
+ else
+ begin
+ rss.output_encoding = encoding
+ rescue RSS::UnknownConversionMethodError
+ error($!) if verbose
+ end
+ feeds << rss
+ end
+end
+processing_time = Time.now - before_time
+
+rss = RSS::Maker.make("1.0") do |maker|
+ maker.encoding = encoding
+ maker.channel.about = "http://example.com/blend.rdf"
+ maker.channel.title = "blended feeds"
+ maker.channel.link = "http://example.com/"
+ maker.channel.description = "blended feeds generated by RSS Parser"
+
+ feeds.each do |feed|
+ feed.items.each do |item|
+ item.setup_maker(maker)
+ end
+ end
+ maker.items.do_sort = true
+ maker.items.max_size = 15
+end
+puts rss
+
+STDERR.puts "Used XML parser: #{RSS::Parser.default_parser}"
+STDERR.puts "Processing time: #{processing_time}s"