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/re_read.rb
kou b2270e5535 * lib/rss/rss.rb: moved copyright description to lib/rss.rb.
* lib/rss.rb: added for convenience.

* sample/rss/re_read.rb: added #to_s sample.

* sample/rss/blend.rb: use 'require "rss"' instead of 'require "rss/*"'.
* sample/rss/list_description.rb: ditto.
* sample/rss/rss_recent.rb: ditto.
* sample/rss/tdiary-plugin/rss-recent.rb: ditto.

* sample/rss/tdiary-plugin/rss-recent.rb: 0.0.6 -> 0.0.7.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-07-22 06:14:48 +00:00

64 lines
1.2 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require "rss"
def error(exception)
mark = "=" * 20
mark = "#{mark} error #{mark}"
puts mark
puts exception.class
puts exception.message
puts exception.backtrace
puts mark
end
verbose = false
before_time = Time.now
ARGV.each do |fname|
if fname == '-v'
verbose = true
next
end
source = nil
File.open(fname) do |f|
source = f.read
end
rss = nil
read = false
begin
rss = RSS::Parser.parse(source)
puts "Re-read valid RSS: #{fname}"
RSS::Parser.parse(rss.to_s)
read = true
rescue RSS::InvalidRSSError
error($!) if verbose
## do non validate parse for invalid RSS 1.0
begin
rss = RSS::Parser.parse(source, false)
rescue RSS::Error
## invalid RSS.
error($!) if verbose
end
rescue RSS::Error
error($!) if verbose
end
if rss.nil?
puts "Invalid RSS: #{fname}"
elsif !read
puts "Re-read invalid RSS: #{fname}"
begin
RSS::Parser.parse(rss.to_s)
rescue RSS::Error
puts " Error occurred: #{fname}"
error($!) if verbose
end
end
end
processing_time = Time.now - before_time
puts "Used XML parser: #{RSS::Parser.default_parser}"
puts "Processing time: #{processing_time}s"