1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/sample/rss/blend.rb
kou 4ef7ec62ca * lib/rss/maker/taxonomy.rb: implemented taxonomy module for RSS
Maker.
* lib/rss/taxonomy.rb: supported RSS Maker.
* lib/rss/maker.rb: added taxonomy module support.

* lib/rss/rss.rb: adjusted to other element API.
* lib/rss/1.0.rb: adjusted to other element API but backward
  compatibility is reserved.
* lib/rss/0.9.rb: ditto.

* test/rss/test_maker_taxo.rb: added test case for taxonomy module
  for RSS Maker.
* test/rss/test_setup_maker_1.0.rb: added tests for taxo:topic.

* test/rss/test_setup_maker_1.0.rb: added backward compatibility
  test.
* test/rss/test_setup_maker_0.9.rb: ditto.
* test/rss/test_setup_maker_2.0.rb: ditto.

* test/rss/rss-testcase.rb: added convenience method for setting
  up taxo:topic.
* test/rss/rss-assertions.rb: added assertion for taxo:topic.

* sample/rss/blend.rb: followed new API.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-11-23 09:24:17 +00:00

73 lines
1.6 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require "rss"
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.items)
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"