From 4700bfa64e1e37edb15f0e847495c94232a513f6 Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 22 Jul 2005 06:14:48 +0000 Subject: * 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: http://svn.ruby-lang.org/repos/ruby/trunk@8820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/rss/blend.rb | 5 +-- sample/rss/list_description.rb | 4 +-- sample/rss/re_read.rb | 64 ++++++++++++++++++++++++++++++++++ sample/rss/rss_recent.rb | 4 +-- sample/rss/tdiary_plugin/rss-recent.rb | 18 +++------- 5 files changed, 71 insertions(+), 24 deletions(-) create mode 100755 sample/rss/re_read.rb (limited to 'sample/rss') diff --git a/sample/rss/blend.rb b/sample/rss/blend.rb index 2aa30d7fc..e578f26a8 100755 --- a/sample/rss/blend.rb +++ b/sample/rss/blend.rb @@ -1,9 +1,6 @@ #!/usr/bin/env ruby -require "rss/1.0" -require "rss/2.0" -require "rss/dublincore" -require "rss/maker" +require "rss" feeds = [] verbose = false diff --git a/sample/rss/list_description.rb b/sample/rss/list_description.rb index ac1db099c..bb1f9636e 100644 --- a/sample/rss/list_description.rb +++ b/sample/rss/list_description.rb @@ -10,9 +10,7 @@ class String end end -require "rss/1.0" -require "rss/2.0" -require "rss/dublincore" +require "rss" channels = {} verbose = false diff --git a/sample/rss/re_read.rb b/sample/rss/re_read.rb new file mode 100755 index 000000000..c19a5099b --- /dev/null +++ b/sample/rss/re_read.rb @@ -0,0 +1,64 @@ +#!/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" diff --git a/sample/rss/rss_recent.rb b/sample/rss/rss_recent.rb index 70776c1e8..7821df5c7 100644 --- a/sample/rss/rss_recent.rb +++ b/sample/rss/rss_recent.rb @@ -10,9 +10,7 @@ class String end end -require "rss/1.0" -require "rss/2.0" -require "rss/dublincore" +require "rss" items = [] verbose = false diff --git a/sample/rss/tdiary_plugin/rss-recent.rb b/sample/rss/tdiary_plugin/rss-recent.rb index 7e6aad55e..867851f38 100644 --- a/sample/rss/tdiary_plugin/rss-recent.rb +++ b/sample/rss/tdiary_plugin/rss-recent.rb @@ -20,7 +20,7 @@ require "rss/rss" RSS_RECENT_FIELD_SEPARATOR = "\0" RSS_RECENT_ENTRY_SEPARATOR = "\1" -RSS_RECENT_VERSION = "0.0.6" +RSS_RECENT_VERSION = "0.0.7" RSS_RECENT_HTTP_HEADER = { "User-Agent" => "tDiary RSS recent plugin version #{RSS_RECENT_VERSION}. " << "Using RSS parser version is #{::RSS::VERSION}.", @@ -49,12 +49,12 @@ def rss_recent(url, max=5, cache_time=3600) have_entry = infos.size > 0 && max > 0 - rv << "